Excellent article Artem Taturevich. I had been struggling for getting a face by name on a part in the context of the assembly (for Simulation API). Currently I am looping through all components -> bodies -> faces but IComponent2::GetCorresponding seems to be a good fit to make it a bit more direct.
Thanks again buddy!
Thank you for the feedback
SW should be paying you. Thank you.
What about this case (switching context):
- I have assembly "Assy1"
- in "Assy1" I have subassembly "Assy1-1"
- i activate "Assy1-1.EditAssembly()"
- select plane ... "Front" and insert new part as file "Part1-1" (non virtual)
- get "Part1-1" edit target.
And of course i'll doing this from API.
You can implement this scenario completely form the assembly context, so no need to converting the points. Below is an example:
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
Dim swAssy As SldWorks.AssemblyDoc
Set swAssy = swApp.ActiveDoc
Dim swSubAssm As SldWorks.Component2
Set swSubAssm = swAssy.GetComponentByName("Assy1-1-1")
swSubAssm.Select4 False, Nothing, False
Dim swFrontPlane As SldWorks.Feature
Set swFrontPlane = swSubAssm.FeatureByName("Front Plane")
swFrontPlane.Select2 False, 1
Dim compPath(0) As String
compPath(0) = Left(swAssy.GetPathName(), InStrRev(swAssy.GetPathName(), "\")) & "Part1-1.sldprt"
Dim matrix(15) As Double
Dim coords(0) As String
Dim vComps As Variant
vComps = swAssy.AddComponents3(compPath, matrix, coords)
Dim swPartComp As SldWorks.Component2
Set swPartComp = vComps(0)
swPartComp.Select4 False, Nothing, False
And here is the result:
Artem Taturevych wrote:
I will be writing and sharing series of articles related to the fundamental concepts of SOLIDWORKS API.
I will start with Assembly Context. This article explains what is assembly and model context, how to edit part in the context of the assembly, how to convert the pointers between contexts.
Please let me know if you have any questions.
I've been following you about the work you have on writing API topic
It'd be nice if you can save all your works on PDF in form of eBook so the users can download at one
I was thinking to introduce some interactive content in the web-site in future and I also modifying those articles/examples quite often which might be a bit problematic to handle in PDF or any static format. But there are several online tools which can turn web-site into the PDF so it can be taken offline.