Hi there,
I am attempting to create a macro to automate the CAD creation.
However, the ruled surface created is not in the intended direction.
Shown here is my code:
boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.135976039502168, -2.97543949024544E-02, -2.66014941007029E-02, True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Split Line1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.135976039502168, -2.97543949024544E-02, -2.66014941007029E-02, True, 4, Nothing, 0)
Set myFeature = Part.FeatureManager.InsertRuledSurfaceFromEdge2(2, 0.002, True, False, True, 1.74532925199433E-02, False, 1, 0, 0, True)
I tried searching through the Solidwork API help and obtained the following:
Function InsertRuledSurfaceFromEdge2( _
ByVal Type As System.Integer, _
ByVal Length As System.Double, _
ByVal FlipPullDir As System.Boolean, _
ByVal FlipDir As System.Boolean, _
ByVal TrimAndSew As System.Boolean, _
ByVal Angle As System.Double, _
ByVal CoordInput As System.Boolean, _
ByVal X As System.Double, _
ByVal Y As System.Double, _
ByVal Z As System.Double, _
ByVal BConnectSurface As System.Boolean _
) As Feature
Parameters
- Type
- 0 = Tangent to Surface
- 1 = Normal to Surface
- 2 = Tapered to Vector
- 3 = Perpendicular to Vector
- 4 = Sweep
- Length
Distance at which to create the surface; valid for Tangent to Surface, Tapered to Vector, Perpendicular to Vector, and Sweep types only
- FlipPullDir
True to flip the pull direction, false to not; valid for Normal to Surface and Tapered to Vector types only
- FlipDir
True to flip the direction, false to not; valid for Perpendicular to Vector type only
So as per my understanding, I need to change the value highlighted in Bold to get it working.
Set myFeature = Part.FeatureManager.InsertRuledSurfaceFromEdge2(2, 0.002, True, False, True, 1.74532925199433E-02, False, 1, 0, 0, True)
However, no matter setting it to true or false, the direction remains the same when the CAD regenerates it.
Please help out if anyone knows what went wrong.
Attached is the CAD generated and also the intended direction highlighted by the red arrow
Question 2:
I tried using an axis as axis of rotation for a revolve feature. However, by default Solidworks keep selecting Line 1 as the axis of rotation.
Can anyone highlight to me how it went wrong?
boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.InsertAxis2(True)
boolstatus = Part.Extension.SelectByID2("Axis1", "AXIS", 0.18776175280219, -4.57444655741727E-02, -6.80012031347362E-02, True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Axis1", "AXIS", 0.18776175280219, -4.57444655741727E-02, -6.80012031347362E-02, True, 16, Nothing, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureRevolve2(True, False, False, False, True, False, 0, 0, 3.1415926535898, 0, False, False, 0.01, 0.01, 0, 0, 0, True, True, True)
Using edit feature it shows that the revolve is based on Line1 instead. I attached the macro file and also the image showing how it went wrong.
Question 3:
As I worked further through the coding, I encountered another issues.
Based on solidwork API help, the code for boundary surface is as below:
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.ClearSelection2 True
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
boolstatus = swModelDocExt.SelectByID2("", "EDGE", -9.640234260928E-04, 0.001963504230389, -0.006514073359085, False, 1, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("", "EDGE", -0.008533278872939, 0.001995620498424, -0.01250000018626, True, 2, Nothing, 0)
Set swFeatMgr = swModel.FeatureManager
swFeatMgr.SetNetBlendCurveData 0, 0, 0, 0, 1, True
swFeatMgr.SetNetBlendDirectionData 0, 32, 0, False, False
swFeatMgr.SetNetBlendCurveData 1, 0, 0, 0, 1, True
swFeatMgr.SetNetBlendDirectionData 1, 32, 0, False, False
swFeatMgr.InsertNetBlend 2, 1, 1, False, 0.0001, False, True, True, True, False, -1, -1, False, -1, False, False, -1, False, False, True
End Sub
However, when I try to use macro to record, this is what I get instead:
' Creating the handle
boolstatus = Part.Extension.SelectByID2("Unknown", "SELOBJGROUP", 0.12514702148872, -7.58034062993182E-02, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Unknown", "SELOBJGROUP", 0.157592211219557, -4.89823493087663E-02, 0, True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sketch4", "SKETCH", 0.125, -0.11, 0, False, 4097, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Unknown", "SELOBJGROUP", 0.12514702148872, -7.58034062993182E-02, 0, True, 12290, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Unknown", "SELOBJGROUP", 0.157592211219557, -4.89823493087663E-02, 0, True, 24578, Nothing, 0)
Set myFeature = Part.FeatureManager.SetNetBlendCurveData(0, 0, 0, 0, 1, True)
Set myFeature = Part.FeatureManager.SetNetBlendDirectionData(0, 32, 0, False, False)
Set myFeature = Part.FeatureManager.SetNetBlendCurveData(1, 0, 0, 0, 1, True)
Set myFeature = Part.FeatureManager.SetNetBlendCurveData(1, 1, 0, 0, 1, True)
Set myFeature = Part.FeatureManager.SetNetBlendDirectionData(1, 32, 0, False, False)
Set myFeature = Part.FeatureManager.InsertNetBlend(2, 1, 2, False, 0.0001, False, True, True, True, False, -1, -1, False, -1, False, False, -1, False, -1, True)
End Sub
Doing a side by side comparison will tell the difference:
swFeatMgr.InsertNetBlend 2, 1, 1, False, 0.0001, False, True, True, True, False, -1, -1, False, -1, False, False, -1, False, False, True
Set myFeature = Part.FeatureManager.InsertNetBlend(2, 1, 2, False, 0.0001, False, True, True, True, False, -1, -1, False, -1, False, False, -1, False, -1, True)
the one in API example has 2 more parameter than the one I record in macro.
I keep getting the error:
"automation error the object invoked has disconnected" when running my macro. and adding in the two extra parameters lead to another error:
"Wrong number of arguments or invalid property assignment"....
Appreciate any form of help from the community out there. Thanks