Evert Vandeberg Posted July 6, 2023 Share Posted July 6, 2023 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))) Quote Link to comment
MullinRJ Posted July 6, 2023 Share Posted July 6, 2023 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 Quote Link to comment
Pat Stanford Posted July 6, 2023 Share Posted July 6, 2023 @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. Quote Link to comment
JBenghiat Posted July 6, 2023 Share Posted July 6, 2023 Unless you need a specially formatted text file, you can also make a worksheet that displays this data, and then export the worksheet. Quote Link to comment
Evert Vandeberg Posted July 6, 2023 Author Share Posted July 6, 2023 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”? Quote Link to comment
Evert Vandeberg Posted July 6, 2023 Author Share Posted July 6, 2023 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? Quote Link to comment
JBenghiat Posted July 6, 2023 Share Posted July 6, 2023 Here is the function Pat was referring to. https://developer.vectorworks.net/index.php/VS:Get3DCntr Modify collect() to pass the handle to Get3DCntr, and add the coordinates to the list as a tupple. Quote Link to comment
Evert Vandeberg Posted July 7, 2023 Author Share Posted July 7, 2023 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)) Quote Link to comment
Jayme McColgan Posted August 30, 2023 Share Posted August 30, 2023 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 Quote Link to comment
Recommended Posts
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.