API - Auto size ref. planes in a part
API - Auto size ref. planes in a part
(OP)
Hi, what I try to do is to make "Autosize" all the ref. planes in the part as it is done with RMB and "Autosize".
The macro is running without errors but the job is not done.
I would appreciate some help, 10x!
'==========================================The Code======
Sub Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.feature
Dim rfPl As SldWorks.RefPlaneFeatureData
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeature = swModel.FirstFeature
Do While Not swFeature Is Nothing
Debug.Print swFeature.GetTypeName
If swFeature.GetTypeName = "RefPlane" Then
Set rfPl = swFeature.GetDefinition
rfPl.autoSize = True
End If
Set swFeature = swFeature.GetNextFeature
Loop
MsgBox ("Finish")
End Sub
==================================================
The macro is running without errors but the job is not done.
I would appreciate some help, 10x!
'==========================================The Code======
Sub Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.feature
Dim rfPl As SldWorks.RefPlaneFeatureData
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeature = swModel.FirstFeature
Do While Not swFeature Is Nothing
Debug.Print swFeature.GetTypeName
If swFeature.GetTypeName = "RefPlane" Then
Set rfPl = swFeature.GetDefinition
rfPl.autoSize = True
End If
Set swFeature = swFeature.GetNextFeature
Loop
MsgBox ("Finish")
End Sub
==================================================






RE: API - Auto size ref. planes in a part
After the line "rfPl.autoSize = True" you need to insert the following line:
bRet = swFeature.ModifyDefinition(rfPl, swModel, Nothing)
(Of course, make sure you specify bRet as a boolean.)
What this does is apply the feature data changes you made to the feature itself. Now for the bad news: Even after you add this line, it still won't autosize your planes. So that means I'm missing something too, right? Well, I don't think so. The reason I say that is because I created a reference plane in addition to the Front, Top and Side that already exist, and I was able to flip it about its reference plane by changing the "ReverseDirection" data field. Once I had that working, I added the line to change the "AutoSize" data field as well. It did not work. I was able to create new planes that were autosized; I just couldn't autosize existing ones.
Unless I'm seriously missing something, this would appear to be a bug in the API.
RE: API - Auto size ref. planes in a part