Jump to content

My intention is to create a script in python where I select self-inserted 3dlocus points. From this selection I need the X,Y and Z coordinates .


Recommended Posts

My intention is to create a script where I select self-inserted 3dlocus points.
From this selection I need the X,Y and Z coordinates .
I want to export this list to a txt file.
Below is my attempt.

Can you help me with this?

Thanks in advance.

 


xwaarde= vs.XCoordinate("(T=LOCUS3D) AND (SEL=True)")
ywaarde= vs.YCoordinate("(T=LOCUS3D) AND (SEL=True)")
zwaarde= vs.ZCoordinate("(T=LOCUS3D) AND (SEL=True)")
CountValue = vs.Count("(T=LOCUS3D) AND (SEL=True)")


vs.Message("xwaarde ",xwaarde ," ywaarde ",ywaarde," zwaarde ",zwaarde, " Totaal locuspunten ",CountValue)

 

# Is this the way?

OBJECTS = []

def collect(handle):
    OBJECTS.append(handle)

vs.ForEachObject(collect, '((VSEL=TRUE))')

vs.AlrtDialog('Num selected objects: {}'.format(len(OBJECTS)))


 

Link to comment

@Evert VandebergI think that @MullinRJ has provided the best solution for getting a list (I am a Pascal guy, not a Python guy and can never remember the difference between lists, dict, and all the other various Python data structure), but he did not include how to get the locations of the loci.

 

Rather than use the X/Y/ZCoordinate functions, I would recommend using the vs.Get3DCenter which will return the X, Y, Z values for a point with a single call. It also take a handle you you would just iterate through Raymond's OBJECTS "list" and pass the collected handles to vs.Get3DCenter.

 

 

 

 

Link to comment
12 minutes ago, Pat Stanford said:

@Evert VandebergI think that @MullinRJ has provided the best solution for getting a list (I am a Pascal guy, not a Python guy and can never remember the difference between lists, dict, and all the other various Python data structure), but he did not include how to get the locations of the loci.

 

Rather than use the X/Y/ZCoordinate functions, I would recommend using the vs.Get3DCenter which will return the X, Y, Z values for a point with a single call. It also take a handle you you would just iterate through Raymond's OBJECTS "list" and pass the collected handles to vs.Get3DCenter.

 

 

What is Raymond’s OBJECT “list”?

 

 

Link to comment
42 minutes ago, MullinRJ said:

Hello @Evert Vandeberg,

 

   Try this:

OBJECTS = []

def collect(handle):
    OBJECTS.append(handle)
    
vs.ForEachObject(collect, 'VSEL & (T=LOCUS3D)')
vs.AlrtDialog('Num selected objects: {}'.format(len(OBJECTS)))


 

Raymond

 

 

I need a list that I can then feed into pycharm so that I can do calculations with this list. Do you have a suggestion on how I should handle this. The code returns a list with all handles in it. How do I extract the coordinates and put them in a list?

Link to comment
17 hours ago, Pat Stanford said:

@Evert VandebergI think that @MullinRJ has provided the best solution for getting a list (I am a Pascal guy, not a Python guy and can never remember the difference between lists, dict, and all the other various Python data structure), but he did not include how to get the locations of the loci.

 

Rather than use the X/Y/ZCoordinate functions, I would recommend using the vs.Get3DCenter which will return the X, Y, Z values for a point with a single call. It also take a handle you you would just iterate through Raymond's OBJECTS "list" and pass the collected handles to vs.Get3DCenter.

 

 

 

 

Thanks for the tip.
I am a beginner and I managed.
Below is the code.

 

import os # hier wordt het operating system van apple geladen om de bestanden te kunnen aanmaken
import vs #dit mag aanstaan of afstaan

OBJECTS = []

def collect(handle):
    OBJECTS.append(handle)

"""
UITLEG: vs.ForEachObject(collect, '((T=LOCUS3D) AND (SEL=True))') 
De functie "collect" wordt geactiveerd en ALLES wordt verzamelt [handle1, handle2, handle3.....] (ook bijvoorbeeld polylijnen (handle 3))
Hier kunnen ook andere objecten (bijvoorbeeld polylijnen) inzitten maar het 2de argument bestaande uit 2 voorwaarden,  filtert de 3d-locussen eruit binnen de selectie[handle1, handle2,.....] eruit.
Omdat handle 3 een polylijn is wordt deze eruit gefiltert

"""

vs.ForEachObject(collect, '((T=LOCUS3D) AND (SEL=True))') # de voorwaarden moeten in een STRING staan

coordinaten = []

for obj in OBJECTS:
    center = vs.Get3DCntr(obj)
    if len(center) == 2:  # Controleer of er X- en Y-coördinaten zijn
        x, y = center[0]  # Haal X- en Y-coördinaten uit de center tuple
        coordinaten.append((x, y))

# Bepaal de uitvoermap en het bestandspad
output_folder = '/Users/evertvandeberg/Documents/dossier'  # Vervang dit door de gewenste uitvoermap
output_file = os.path.join(output_folder, 'locuspunten.txt')

# Schrijf de coördinaten naar het tekstbestand
with open(output_file, 'w') as file:
    for i, coord in enumerate(coordinaten):
        if i != 0:
            file.write(', ')
        file.write('{}'.format(coord))

vs.AlrtDialog('Locuspunten zijn geëxporteerd naar {}'.format(output_file))

Link to comment
  • 1 month later...

if you want another view... this is how I pull info for selected objects. 

 

import vs
objects = []

### Main Runner
def start():
        vs.ForEachObject(collect, '((VSEL=TRUE))')
        vs.AlrtDialog(str(objects))

### Collect all the selected items and sort them
def collect(handle):
        hrecdef = vs.GetParametricRecord(handle)
        recname = vs.GetName(hrecdef)

        if recname == "3D Locus":
            fpoint_info = []
            fpoint_info.append(handle)
            fpoint_info.append(vs.GetLocus3D(handle))
            objects.append(fpoint_info)

        return None

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...