AlHanson Posted June 12, 2021 Share Posted June 12, 2021 I'm building a simple tool that just does a distribute along path for an object, but it can end up drawing hundreds or thousands of each object along the path depending on the length and at these larger quantities it gets a little slow and cumbersome. This process works better way better just inserting a symbol since all these objects are the same anyway. Rather than having to import this symbol from some external resource file, I've just adapted the original draw script to create a symbol definition resource if its already in the resource library. The problem I'm running into is that if I try to run the create symbol script inside my object the custom object path gets swept up by the script and embedded into the symbol which will then break the rest of the script as the path is no longer part of the PIO. I'm not even sure how this is happening as the vs.BeginSym trigger comes well after the path creation and processing. I've tried moving the symbol creation trigger to a couple different points in the script/event flow and nothing I've attempted prevents this. Does anybody have any recommendations on how to avoid this, or a specific event to handle this creation, or just a better way to avoid creating a symbol? Quote Link to comment
Pat Stanford Posted June 14, 2021 Share Posted June 14, 2021 If you can share the script we will have a better chance of helping you figure it out. Quote Link to comment
AlHanson Posted June 14, 2021 Author Share Posted June 14, 2021 Thanks Pat. Here's the simplified code for reference. This would be part of a 2D path PIO with Events enabled. import vs spacingBetween = 9 bUseSymbol = True markerSymbol = 'Direction Marker' (BOOL, pioName, pioHandle, pioRecordHandle, pioWall) = vs.GetCustomObjectInfo() # ---------------------------------------------------------------------------------------------------------------------- def positionMarkerSymbolResource(): if vs.GetObject(markerSymbol) == 0: # Check if symbol already exits, create symbol if not vs.BeginSym(markerSymbol) positionMarker((0, 0)) vs.EndSym() def positionMarker(pt, rotation=0): markerWidth = 3 markerGroup = vs.BeginGroupN(None) vs.ArcByCenter(pt[0], pt[1], markerWidth/2, 0, 360) # Draw Circle component vs.BeginPoly() # Draw Triangle component vs.MoveTo((pt[0] - markerWidth / 2, pt[1])) vs.LineTo((pt[0] + markerWidth / 2, pt[1])) vs.LineTo((pt[0], pt[1] + markerWidth / 2)) vs.EndPoly() vs.SetPolyClosed(vs.LNewObj(), True) # Close Triangle vs.SetFillBack(vs.LNewObj(), (0, 0, 65535)) # Set Triangle Color vs.EndGroup() vs.HRotate(markerGroup, pt, rotation) # Rotate Marker Group return markerGroup def main(): pathHandle = vs.HDuplicate(vs.GetCustomObjectPath(pioHandle), 0, 0) vs.SetFPat(pathHandle, 0) # No Fill pathLength = vs.HLength(pathHandle) # Length of Path ptCount = int(pathLength // spacingBetween) + 1 # Max Count by spacing for i in range(ptCount): distance = spacingBetween * i #Distance per step (b, pt, tangent) = vs.PointAlongPoly(pathHandle, distance) rotation = vs.Vec2Ang(tangent)+90 if bUseSymbol: positionMarkerSymbolResource() # Check Symbol Resource vs.Symbol(markerSymbol, pt, rotation) # Insert Symbol else: positionMarker(pt, rotation) # Draw non symbol Marker # ----------------------------------------EVENTS------------------------------------------------------------------------ kObjOnInitXProperties = 5 kObjOnWidgetPrep = 41 kParametricRecalculate = 3 kObjOnSpecialEditID = 7 kObjXPropSpecialEdit = 3 kReshapeSpecialEdit = 3 kObjXPropEditGroup = 1 kObjXPropEditGroupPath = 2 def execute(): (theEvent, theButton) = vs.vsoGetEventInfo() if theEvent == kObjOnInitXProperties: vs.SetObjPropVS(kObjXPropSpecialEdit, vs.Chr(kReshapeSpecialEdit)) # Double Click Edit Path vs.SetObjPropCharVS(kObjXPropEditGroup, vs.Chr(kObjXPropEditGroupPath)) # Double Click Edit Path if theEvent == kParametricRecalculate: main() if theEvent == kObjOnSpecialEditID: # Double Click Edit Path vs.EditObjectSpecial(pioHandle, 3) # Double Click Edit Path execute() (This basic script could also be a good starting reference for anybody looking for help creating a simple duplicate along path in the future) Quote Link to comment
Pat Stanford Posted June 23, 2021 Share Posted June 23, 2021 I am not certain, (my Vectorscript Foo is far stronger than my Python), but why are you duplicating the path object? Quote pathHandle = vs.HDuplicate(vs.GetCustomObjectPath(pioHandle), 0, 0) My guess is that you should just be reusing the existing path instead. Quote Link to comment
AlHanson Posted June 23, 2021 Author Share Posted June 23, 2021 A fair point to explore- that was the only way I could figure out how to make the path a visible element in the drawing when I was getting started with my scripting and I've just continued to do it as it was working, but it does seem like there has to be a better way of approaching this that I'm missing- perhaps by some preference setting I haven't found yet? I never dug any deeper into that once the duplication solved the initial hurdle. That said, getting rid of the duplication doesn't help the situation and the initial path object is still grabbed by the symbol creation so it's just one less Handle variable is NIL error in the initial output until the symbol is created. Quote Link to comment
Pat Stanford Posted June 23, 2021 Share Posted June 23, 2021 Can you post (or DM me) the PIO file so I can add it to my workspace. I tried making it from the code you posted, but I don't think I got it right as I could not get it to run. Quote Link to comment
AlHanson Posted June 23, 2021 Author Share Posted June 23, 2021 Here's the PIO file. I think this is all you need? I haven't really gotten around to figuring out portability yet. 😆 PathExample.vso 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.