AnsweredAssumed Answered

Using GetEditTarget Method and pointers

Question asked by Austin Schukar on Nov 4, 2019
Latest reply on Nov 7, 2019 by Austin Schukar

Hi everyone,




Being a bit new to SW VBA, I have been getting my feet wet with some sketch editing, face/surface commands, etc. but I have really been struggling to understand the usage of pointers and selections when working with different assemblies and parts.




I currently have a macro that will perform the following steps (so far):


  1. Find the user-selected 3D sketch "point cloud." (In my case, I manually select "Scanned" point cloud after prompting)
  3. Store all of the points from the existing 3D sketch, then exit sketch.
  5. Create new 3D sketch and prompts user to select a face (prompted to select a new face) on the "Ref Panel" part file.
  7. Do some calculations with the point coordinates to plot points and lines that lie normal to and on the user-selected faces.








This will just drop the new 3D sketch in the same part that the user-selected sketch lies and seems to work just fine. Several of the design guys and I will be using this macro in different contexts. We sometimes are forced to use large sub-assemblies, and we all could be using the same "skeleton" part files to build our designs.




To make things smooth and care-free, I am trying to figure out how to get the macro to create the new 3D sketch "Closest Point Cloud...." in whichever file is currently being edited. So in a perfect world I would be editing a sub-assembly, select "Scanned" point cloud, edit the sketch, grab points, exit sketch, edit the sub-assembly that I was in, insert new sketch. Say I'm editing Assem1^Test2, and I want to run the macro while editing, to create the new 3D sketch in this virtual assembly. Or say I'm editing Ref Panel, and want to create the new 3D sketch in that file.






I have the macro checking if the Active Document is a Part/Assembly file for my next steps. Then if it finds that the Active Doc is an Assembly file, it searches for the file being edited in-context by using SldWorks.ModelDoc2.GetEditTarget Method. I can't for the life of me seem to be able to determine which steps I need to take to use this target's pointer to call later. Having been stuck for a whole afternoon yesterday and morning today has been pretty mind-numbing.




From the time that I find the ModelDoc using GetEditTarget, should I be looking into Persistent References, or can I get ID's of the Assembly/Part that is currently being edited so that I know which Assembly/Part to come back to for edit? If anyone has any tips on my approach, any advice would be extremely helpful.


Edit: Apologies in advance for errors in nomenclature. Hopefully this question is clear enough to get the picture.


Thanks in advance,