Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About relume

  • Rank

Personal Information

  • Location

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello please find two scripts that I have created as part of libs: # use : assigns a new layer to object def object_layer_assign(vObject_Handle, vLayer_Destination_Name): vLayer_Destination_Handle = vs.GetLayerByName(vLayer_Destination_Name) if vLayer_Destination_Handle == None: vLayer_Actual_Handle = vs.ActLayer() vLayer_Actual_Name = vs.GetLName(vLayer_Actual_Handle) vs.Layer(vLayer_Destination_Name) vLayer_Destination_Handle = vs.ActLayer() vs.Layer(vLayer_Actual_Name) vs.SetParent(vObject_Handle, vLayer_Destination_Handle) and : # use : assigns a new layer to objects selected by criteria def object_layer_assign_criteria(vSelection_Criteria, vLayer_Destination_Name): vLayer_Destination_Handle = vs.GetLayerByName(vLayer_Destination_Name) if vLayer_Destination_Handle == None: vLayer_Actual_Handle = vs.ActLayer() vLayer_Actual_Name = vs.GetLName(vLayer_Actual_Handle) vs.Layer(vLayer_Destination_Name) vLayer_Destination_Handle = vs.ActLayer() vs.Layer(vLayer_Actual_Name) def object_layer_assign_iterator(vObject_Handle): vs.SetParent(vObject_Handle, vLayer_Destination_Handle) vs.ForEachObject(object_layer_assign_iterator, vSelection_Criteria) I hope they will be to your help, best regards,
  2. Hello With VW2019 I came across, that in my example file "viewport.vwx" the Python-Script "with visibility" to generate a ViewPort and to assign to it the layer visibility to active will crash VW2019. If the created ViewPort is manually deleted VW2019 will crash. So in the loop to assign the layer's visibility to active a condition has to assure, that the visibility is only set to design layers (many thanks to D. Corpataux from ComputerWorks.ch). So in the attachment there is a new stable Script named "with viability stable VW2019". best regards viewport_v2.vwx # python-script : "with visbility stable VW2019" import vs def createviewport(ModuleLayer, objectHandle): vs.Layer(ModuleLayer) # make sure we are on the correct starting layer # screenName = objectList[selectedObjects][0] # Gets the Screen Name - 1st item in t = (screenName,objectHandle) # objectHandle = objectList[selectedObjects][1] # Gets the Object Handle - 2nd item in t = (screenName,objectHandle) # Get the object height, width and bounding box of object p1, p2 = vs.GetBBox(objectHandle) objectWidth = vs.HWidth(objectHandle) objectHeight = vs.HHeight(objectHandle) #Create VP Crop Object vs.Rect(p1, p2, objectWidth, objectHeight) vpCrop = vs.LNewObj() # Create the layer and set the layer name layerHandle = vs.CreateLayer('01', 2) # using 01 forces the next unused sheet nubmer to be used layerName = vs.GetLName(layerHandle) # get they layer name. It appears the layer name is the sheet number #vs.SetObjectVariableString(layerHandle, 159,'Module Layout - ' + screenName) vs.SetObjectVariableString(layerHandle, 159,'Module Layout - ' ) # vs.Rect(0,0,10,10) # test to see if something draws on the sheet layer #Create the VP and set Crop Object vpHandle = vs.CreateVP(layerHandle) vs.SetVPCropObject(vpHandle, vpCrop) vs.SetObjectVariableReal(vpHandle, 1003, 32) #set scale to a default of 32 ## set class and layer visibility to viewport object vClassNum = vs.ClassNum() for vClassNumIndex in range(1, vClassNum+1): vs.SetVPClassVisibility(vpHandle, vs.ClassList(vClassNumIndex), 0) vLayer_handle = vs.FLayer() while vLayer_handle != None: vLayer_Type = vs.GetObjectVariableInt(vLayer_handle, 154) #Design Layer or Sheet Layer if vLayer_Type == 1: # Design Layer vs.SetVPLayerVisibility(vpHandle, vLayer_handle, 0) vLayer_handle = vs.NextLayer(vLayer_handle) viewPort_X, viewPort_Y = vs.HCenter(vpHandle) print(viewPort_X, " ", viewPort_Y) ModuleLayer = "test" vs.DSelectAll() vs.SelectObj("(ALL)") vs.Group() vGroup_handle = vs.LSActLayer() createviewport(ModuleLayer, vGroup_handle) vs.HUngroup(vGroup_handle)
  3. Hello Thank very much you for your hints and considering my questions. The command vs.CallTool() is not applicable, because I have to use an allready existent polygon as selection perimeter and do not want any user inteaction. Iterating over every point to check by vs.PtInPoly if it is on/witin the actual polygon is some kind of "brute force", as I have to iterated first over every polygon an then itereate over all points to be checked for each polygon. But it seems that there is no other approach to do it. I wondered if there would be any VW criteria to select objects by a x/y range (select all objects where x/y is >= as xTop/yTop AND x/y is <= xBottom/yBottom) in order to optimise somebit the iteration process by reducing the amount of relevant points to check after in detail if they are within a certain polygon. But unfortunately such numerical/grafical criteria search is not available in VW as it is part of every GIS-tool. By looking again at the VW search criterias I found the "location" critearia. If an object has a given name, it is possible to formulate a search criteria that looks for points/objects that are within the object with the given name: import vs vs.DSelectAll() vs.SelectObj("(INSYMBOL & INOBJECT & (L='LayerToSearchIn') & (LOC='MySelectionPolygon'))"); With this search criteria the solution is much easier (I do not know the details about performance differences) but of course for every polygone to test a name (a temporary unique name) has to be given: import vs def searchPoints_for_MyPolygon(vMyPolygon_handle): # the original name of the object to be processed has to be retrieved vMyPolygon_Name_org = vs.GetName(vMyPolygon_handle) vMyPolygon_Name_temp = 'MyPolygon_temp_unique_name' vs.SetName(vMyPolygon_handle, vMyPolygon_Name_temp) # a temp. unique name has to be given for the case the name = "" for correct selection vSelectionCriteria_Points = "(INSYMBOL & INOBJECT & (L='LayerToSearchIn') & (LOC='"+vMyPolygon_Name_temp+"'))" vPointsFound = vs.Count(vSelectionCriteria_Points) vs.SelectObj(vSelectionCriteria_Points) vs.AlrtDialog("Points found: " + str(vPointsFound)) vs.SetName(vMyPolygon_handle, vMyPolygon_Name_org) # the original object name has to be reassigned vs.DSelectAll() vSelectionCriteria_MyPolygons = "INSYMBOL & INOBJECT & (L='LayerWithMyPolygons')" vs.ForEachObject(searchPoints_for_MyPolygon,vSelectionCriteria_MyPolygons) vs.AlrtDialog('finished') best regards, relume
  4. Hello I am back 😐 to the recurrent problem of finding/selecting points or other 2D objects within an other 2D polygon or polyline. As long the number of points to be selected are small or smaller than the number of the "selecting" 2D polygons, then I can iterate over every point to check if it is inside a "selecting" 2D polygon by "vs.FindObjAtPt_GetObj". But if I have a (very) large number of points and a smaller number of "selecting" 2D polygons the above approach is inappropriate, due to the huge iteration over every point. So I thought I would be possible to use/adopt the polygon selection tool to "embrace" the relevant points (to be found) by a 2D polygon. But actually I can not see any way how to script this – how to get by scripting a given 2D polygon in to the polygon selection tool to "embrace" the relevant points. I would appreciate any idea how to get the problem solved, many thanks in advance, relume
  5. Hello I am using my script for producing many small plats in a batch (moving window on every object) to export each to its own pdf for many years - first in VectorScript and now ported to Python. It works without problems. I do not need to ResetObject() nor ReDrawAll(). In general I do not see any greate difference to your code. The only difference in my script is, that I am using a predefined presentation layer and reusing it for every plat to be drawn and exported. But I do not think that this is the problem. I tried and slightly adapted your code (see attachment) and the only proble that I can see is, that vs.CreateVP() creates a ViewPort-Object with no layer and class activation (they are all set to invisible). So running your code I get also this square with the red cross in it. But when I assign class and layer visibility to active for this ViewPort-Object the bounding box of the viewport change to its real dimensions and location. Thus assigning class and layer visibility is "indispensable" to get the correct result, although the square with the red cross seems to be a temporarily "artifact" with a viewport with all classes and layers set to invisible. Finally the new created viewport has to moved to the page center (or any position) - that is default and is corresponding the manual viewport creation. best regards viewport.vwx
  6. Hello I complete agree with you. I feel all about the same. 🙂
  7. Hello Oh many thanks for your prompt response that helps a lot! http://developer.vectorworks.net/index.php/VS:SetParent vs.SetParent(ObjectHandle, LayerHandle) best regards
  8. Hello perhaps this snippet from a larger script may help: # -- create viewport : move viewport object to page center vs.Layer(vLayerViewPort_name) # selects layer with ViewPort object vViewCenter_x, vViewCenter_y = vs.GetOrigin() # this works as long SheetLayer origin was not altered vViewPort_Rect_center_x, vViewPort_Rect_center_y = vs.HCenter(vViewPort_Object_handle) vViewCenter_x = vViewCenter_x * -1 vViewCenter_y = vViewCenter_y * -1 vDifference_x = (vViewCenter_x-vViewPort_Rect_center_x) vDifference_y = (vViewCenter_y-vViewPort_Rect_center_y) # message("object_process_item : vViewCenter : " + str(vViewCenter_x) + " / " + str(vViewCenter_y) + " | " + str(vViewPort_Rect_center_x)+ " / " + str(vViewPort_Rect_center_y) + " | " + str(vDifference_x)+ " / " + str(vDifference_y)) vObject_type = vs.GetType(vViewPort_Object_handle) if ((vObject_type == 122) or (vObject_type == 3)): vs.HMove(vViewPort_Object_handle, vDifference_x, vDifference_y) best regards
  9. Hello I am wondering if there is an easy assignment command for objects to change layers as it is for classes (vs.setClass or vs.setClassN). Can it be true, that this should be only possible by duplicating the object first (by vs.CreateDuplicateObject) and thereafter deleting the original? In the VW GUI info-Palette with the appropriate pop-list the task seems more as an reasignment than a duplication (or a hidden cut/past operation). Many thanks in advance and best regrads,
  10. Hello Importing many Shape files into a VW document can be very time consuming. So I would like to write a pyhton script, that will take all Shape files from a folder list and import every file into the VW document. On the VectorScript reference page I can find the command "vs.LegacyShapefileImp()" and the description "Use the old UI to import files". There is no example and nor further specification why this is "legacy" and which command is the actual replacement command. Has any body used a new vs command to import Shape files and could therefore reference me the appropriate documentation? Many thanks in advance and best regards, André
  11. Hello So my approach is, also by condoning the issues with the FindObjAtPt_Create (e.g. the function does not search on the objects precise shape but on its bounding box), it the following script (may be it may help others and save time): def object_atPt_list(vPoint_ToSearch, vPoint_ToSearch_Tolerance = 0, vLayers_ToSearch = None, vSelection_Criteria = ''): import vest.base.vw._ vLayer_Active_handle = vs.ActLayer() vLayer_Active_name = vs.GetLName(vLayer_Active_handle) vXorg, vYorg = vs.GetOrigin() vPoint_ToSearch_new_X = vXorg+vPoint_ToSearch[0] vPoint_ToSearch_new_Y = vYorg+vPoint_ToSearch[1] # vs.AlrtDialog('X/Y Org : ' + str(vXorg) + '/' + str(vYorg) + '\n' + 'PointToSearch new X/Y : ' + str(vPoint_ToSearch_new_X) + '/' + str(vPoint_ToSearch_new_Y)) if vLayers_ToSearch is None: vLayers_ToSearch = layers_info_list('visible') vObjects_ToSearch = 0 if vSelection_Criteria != '': vs.DSelectAll() vs.SelectObj(vSearch_Selection_Criteria) vObjects_ToSearch = 2 vObject_Handle_list = list() for vLayers_ToSearch_item in vLayers_ToSearch: vs.Layer(vLayers_ToSearch_item["name"]) vSearch_Container_start = vs.Handle() vSearch_list = vs.FindObjAtPt_Create(vSearch_Container_start, vObjects_ToSearch, 0, vPoint_ToSearch_new_X, vPoint_ToSearch_new_Y, vPoint_ToSearch_Tolerance) # 2 = selected only; 0 = shalow vSearch_list_size = vs.FindObjAtPt_GetCount(vSearch_list) for i in range(vSearch_list_size): vObject_handle = vs.FindObjAtPt_GetObj( vSearch_list, i ) vObject_Handle_list.append(vObject_handle) # vs.AlrtDialog( 'Index: ' + str(i) + '\n' + 'Obj Type: ' + str(vs.GetTypeN(vObject_handle))) vs.FindObjAtPt_Delete( vSearch_list ) if vSelection_Criteria != '': vs.DSelectAll() vs.Layer(vLayer_Active_name) # vs.AlrtDialog ("vest.base.vw.objects.object_atPt_list : vObject_Handle_list : " + str(vObject_Handle_list)) return(vObject_Handle_list) and the called script snippet "layers_info_list" to get a layers list to search in, if the layers list is not provided in the function parameters: def layers_info_list(vVisibility="all"): vLayer_list = list() vLayer_handle = vs.FLayer() vLayer_id = 1 while vLayer_handle != None: vLayer_attributes = {} vLayer_attributes["id"] = vLayer_id vLayer_attributes["handle"] = vLayer_handle vLayer_attributes["name"] = vs.GetLName(vLayer_handle) vLayer_visibility = vs.GetLVis(vLayer_handle) vLayer_attributes["visibility"] = vLayer_visibility vLayer_attributes["scale"] = vs.GetLScale(vLayer_handle) vLayer_attributes["options"] = vs.GetLayerOptions() vLayer_attributes["mode"] = vs.GetLayerRenderMode(vLayer_handle) vLayer_id += 1 if vVisibility == "visible" and vLayer_visibility == 0: # normal vLayer_list.append(vLayer_attributes) elif vVisibility == "visible_all" and (vLayer_visibility == 0 or vLayer_visibility == 2): # normal or grayed vLayer_list.append(vLayer_attributes) elif vVisibility == "grayed" and vLayer_visibility == 2: # grayed vLayer_list.append(vLayer_attributes) elif vVisibility == "invisible" and vLayer_visibility == 1: # invisible vLayer_list.append(vLayer_attributes) elif vVisibility == "all": vLayer_list.append(vLayer_attributes) vLayer_handle = vs.NextLayer(vLayer_handle) return (vLayer_list) best regards
  12. Hello Thank you very much. Yes this is the approach I am considering - although I hopped for a more convenient way. I have addressed the issue with the origin shift already some years ago (see my post (3rd entry) : FindObjAtPt_Create any working example? I have documented the issue with the circle/arc object in the same post (see 4th entry). best regards
  13. Hello Pat Thank you for considering my question. vs.ForEachObjectAtPoint has similiar issues - works only on the active layer and does not enter in grouped objects.
  14. Hello I am still struggling with this very basic geometric search problem. I am looking for an approach to select 2D objects by a 2D point (preferably with a "pick radius") that lays within the objects to be searched/selected or are overlapped by the pick radius. The issues with the vs functions are still the same as reported some years ago: FindObjAtPt_Create any working example? basic but sever issues with the vs.FindObjAtPt_Create functions are: works only on the active layer and not over all layers or a selection of layers (e.g. visible ones) works only if the document origin does not have been moved - that is a very sever issue does not work correctly on arcs and other object types So my question is, are there any alternative approaches now with python to achieve this? Many thanks for any hint and best regards.
  15. Hello I wanted to install the "pandas" library and found problems using the Marionette.VerifyOrGetLib() function but also with the above script from DomC that is similar to the Marionette.VerifyOrGetLib() function. Further for both functions/scripts an URL to a specific version of library to be installed is needed. But pip.main() has the possibility to get the right library version for the VectorWorks Python environment (acutally in VW2018 is 3.5.2). I was able to install the library "numpy" with the following command : pip.main(['install', 'numpy', '--target', vPathToMy_VW_PythonExternals_Folder]) But this did not work for the library "pandas" as the appropriate pip.main() command rised an error saying that there is no correct matching version. But by passing an "-q" parameter "pandas" installs correctly: pip.main(['install', 'numpy', '-q', '--target', vPathToMy_VW_PythonExternals_Folder]) Then I tried also to install "pillow" and it installed also correctly (version 5.0.0) with all dependencies. But there is some problem with probing for correct installation. While the lib distribution is called "pillow", the name to retrieve it with pip.main(), testing the existence and for importing the lib has to be named "PIL". For this reason Morionette.VeriyOrGetLib() does not work. So the installed lib "pillow" has to be tested and imported by: importlib.import_module('PIL') So a script that encompass this problem could be as this: import os import sys import importlib import vs appfolder = vs.GetFolderPath(1) appuserfldr = vs.GetFolderPath(12) cmd = 'Python Externals' if (sys.platform == 'darwin'): pos = appfolder.find(':') appfolder = appfolder[pos:] appfolder = appfolder.replace(':','/') pos = appuserfldr.find(':') appuserfldr = appuserfldr[pos:] appuserfldr = appuserfldr.replace(':','/') cmd = appuserfldr + cmd vs.AlrtDialog("path : " + cmd) if not os.path.exists(cmd): os.makedirs(cmd) #libToimport = 'numpy' #libToimport = 'pandas' libToimport = 'pillow' libToimportAlias = 'PIL' try: importlib.import_module(libToimportAlias) except ImportError: import pip pip.main(['install', '--upgrade', '-q', libToimport, '--target', cmd ]) importlib.import_module(libToimportAlias) try: importlib.import_module(libToimportAlias) exit_code = True vs.AlrtDialog('is installed : '+ libToimport) except ImportError: vs.AlrtDialog('not installed : '+ libToimport) Best regards P.S. And not to forget to reference the python search path to "~/Library/Applications Support/VectorWorks/.../Python Externals"


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

  • Create New...