-
Re: Plan with 3 points
Peter Kennedy Apr 11, 2018 10:47 AM (in response to Mário Neto)Have you looked at this:
2017 SOLIDWORKS API Help - InsertRefPlane Method (IFeatureManager)
Here is an example with with VBA, from what I can see you should be able to add a plane with 3 points:
2017 SOLIDWORKS API Help - Insert Reference Plane Example (VBA)
-
Re: Plan with 3 points
Mário Neto Apr 11, 2018 11:01 AM (in response to Peter Kennedy)Hi Peter,
I'll try it. But just to clarify: When i try to use the "ICreatePlaneThru3Point3" the plane is created, but i get an error. Why do i get an error if the plan is created?
-
Re: Plan with 3 points
Mário Neto Apr 11, 2018 1:53 PM (in response to Mário Neto)As far as i got:
Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swFeature As SldWorks.Feature Dim swSubFeature As SldWorks.Feature Dim swPlaneFeat As SldWorks.Feature Dim swFeatMgr As SldWorks.FeatureManager Dim vSkPtArr As Variant Dim vSkSeg As Variant Dim vConfNameArr As Variant Dim vSuppStateArr As Variant Dim swSkPt As SldWorks.SketchPoint Dim swSkLine As SldWorks.SketchLine Dim value As Boolean Dim boolstatus As Boolean Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swFeature = swModel.FirstFeature While Not swFeature Is Nothing Select Case swFeature.GetTypeName2 Case "FlatPattern" vConfNameArr = swModel.GetConfigurationNames vSuppStateArr = swFeature.IsSuppressed2(swThisConfiguration, vConfNameArr) Debug.Print "Component Flat Pattern Supression = " & vSuppStateArr(i) If vSuppStateArr(i) = True Then value = swFeature.Select(True) value = swModel.EditUnsuppress2 Set swSubFeature = swFeature.GetFirstSubFeature Debug.Print "Feature being processed is: " & swFeature.Name While Not swSubFeature Is Nothing Debug.Print "SubFeature being processed is: " & swSubFeature.Name If swSubFeature.Name Like "*Caixa*" Then Dim swSketch As Sketch Set swSketch = swSubFeature.GetSpecificFeature2 vSkPtArr = swSketch.GetSketchPoints For i = 1 To UBound(vSkPtArr) Set vSkPt = vSkPtArr(i) vSkPt.Select (True) Next i Dim swPlane As Object Set swPlane = swModel.FeatureManager.InsertRefPlane(4, 0, 4, 0, 4, 0) boolstatus = swPlane Is Nothing If boolstatus = True Then Debug.Print "Plane Not Created" Debug.Print "Plane Created" End If Set swSubFeature = swSubFeature.GetNextSubFeature Wend End Select Set swFeature = swFeature.GetNextFeature() Wend End Sub
But the the plan is not created.
If you are goin to test it you might want to change line 58 since i user solidworks in portuguese. It's supposed to call the sheet metal's bounding box
-
Re: Plan with 3 points
Mário Neto Apr 11, 2018 4:38 PM (in response to Mário Neto)Ok, i got it:
Basically, you have to select the points with the SelectByID2 function appending the marks 0, 1 and 2 respectively in your 3 points, then you can call the InsertRefPlane. My code ended up like this:
Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swFeature As SldWorks.Feature Dim swSubFeature As SldWorks.Feature Dim swPlaneFeat As SldWorks.Feature Dim swSk As SldWorks.Feature Dim swFeatMgr As SldWorks.FeatureManager Dim FeatMgr As IFeatureManager Dim vSkPtArr As Variant Dim vSkSeg As Variant Dim vConfNameArr As Variant Dim vSuppStateArr As Variant Dim swSkPt As SldWorks.SketchPoint Dim swSkLine As SldWorks.SketchLine Dim Value As Boolean Dim boolstatus As Boolean Dim SketchName As String Dim PointName As String Dim PointType As String Dim PointSlot As String Dim PointX As Double Dim PointY As Double Dim PointZ As Double Dim Mark As Integer Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swFeature = swModel.FirstFeature While Not swFeature Is Nothing Select Case swFeature.GetTypeName2 Case "FlatPattern" vConfNameArr = swModel.GetConfigurationNames vSuppStateArr = swFeature.IsSuppressed2(swThisConfiguration, vConfNameArr) Debug.Print "Component Flat Pattern Supression = " & vSuppStateArr(i) If vSuppStateArr(i) = True Then Value = swFeature.Select(True) Value = swModel.EditUnsuppress2 Set swSubFeature = swFeature.GetFirstSubFeature Debug.Print "Feature being processed is: " & swFeature.Name While Not swSubFeature Is Nothing Debug.Print "SubFeature being processed is: " & swSubFeature.Name If swSubFeature.Name Like "*Caixa*" Then Dim swSketch As Sketch Set swSketch = swSubFeature.GetSpecificFeature2 vSkPtArr = swSketch.GetSketchPoints Mark = 0 For i = 1 To UBound(vSkPtArr) Set swSkPt = vSkPtArr(i) Set swSk = swSkPt.GetSketch SketchName = swSk.Name PointSlot = swSkPt.IGetID PointType = "EXTSKETCHPOINT" PointX = swSkPt.X PointY = swSkPt.Y PointZ = swSkPt.Z PointName = "Point" & PointSlot & "@" & SketchName Debug.Print "Point Name is: " & PointName Debug.Print "Point Coordinates are: " & PointX; ","; PointY; ","; PointZ Value = swModel.Extension.SelectByID2(PointName, PointType, PointX, PointY, PointZ, True, Mark, Nothing, 0) If Value = False Then Debug.Print "Point " & PointName; " Selected" Mark = Mark + 1 Next i Dim swPlane As Object Set swPlane = swModel.FeatureManager.InsertRefPlane(4, 0, 4, 0, 4, 0) boolstatus = swPlane Is Nothing If boolstatus = True Then Debug.Print "Plane Not Created" Debug.Print "Plane Created" End If Set swSubFeature = swSubFeature.GetNextSubFeature Wend End Select Set swFeature = swFeature.GetNextFeature() Wend End Sub
-
Re: Plan with 3 points
Peter Kennedy Apr 11, 2018 4:43 PM (in response to Mário Neto)Hey Mario sorry I haven't checked in till now, were you able to get plane as intended?
-
Re: Plan with 3 points
Mário Neto Apr 11, 2018 4:52 PM (in response to Peter Kennedy)Hi Peter,
No problem, i struggled but managed to do it, it's working fine, now i'm just polishing it. Thanks for your help, without that function it would sure be much more difficult
-
-
-
-
-