Community
I have figured out how to create a new sweep, but I can't figure out how to modify the path of an existing one (using existing sketches).
See function UpdateSweep() in the code below.
Class Sweep
Dim oDoc As PartDocument
Dim oCompDef As ComponentDefinition
Dim oFeats As PartFeatures
Dim oSweepFeats As SweepFeatures
Sub Main
oDoc = ThisDoc.Document
oCompDef = oDoc.ComponentDefinition
oFeats = oCompDef.Features
oSweepFeats = oFeats.SweepFeatures
If FeatureExists("MySweep") Then oFeats("MySweep").Delete
Call MakeNewSweep("MySweep", "ProfileSketch", {"PathSketch1", "PathSketch2"})
Call UpdateSweep("MySweep", "ProfileSketch", {"PathSketch1", "PathSketch2", "PathSketch3"})
End Sub
Sub MakeNewSweep(sweepName As String, profileSketchName As String, pathSketchNames As String())
Dim oProfileSketch As Sketch = oCompDef.Sketches.Item(profileSketchName)
Dim oProfile As Profile = oProfileSketch.Profiles.AddForSolid
Dim oPath As Path = CreateSketchCurvesPath(pathSketchNames)
Dim oSweep As SweepFeature = oCompDef.Features.SweepFeatures.AddUsingPath(oProfile, oPath, kJoinOperation)
oSweep.Name = sweepName
End Sub
Sub UpdateSweep(sweepName As String, profileSketchName As String, pathSketchNames As String())
Dim oProfileSketch As Sketch = oCompDef.Sketches.Item(profileSketchName)
Dim oProfile As Profile = oProfileSketch.Profiles.AddForSolid
Dim oPath As Path = CreateSketchCurvesPath(pathSketchNames)
Dim oSweepFeat As SweepFeature = oSweepFeats(sweepName)
Dim oSolidSweepDef As SolidSweepDefinition = oSweepFeat.SolidSweepDefinition
Logger.Info(oSweepFeat.Name) 'Displays correct Sweep
Logger.Info(oSolidSweepDef) ' Empty! Can't figure out how to use oSweepFeats.CreateSolidSweepDefinition()
Logger.Info(oPath.Count) 'Displays new path count
'[ No idea where to proceed from this
Dim sweepType As SweepTypeEnum = kPathSweepType
Dim partFeatureOperationEnum As PartFeatureOperationEnum = kJoinOperation
Dim oNewSweepDef As SweepDefinition = oSweepFeats.CreateSweepDefinition(sweepType, oProfile, oPath, partFeatureOperationEnum)
Logger.Info(oNewSweepDef.Path.Count)
']
' This throws error "Object reference not set to an instance of an object." since oSolidSweepDef is empty
oSolidSweepDef.Path = oPath
End Sub
Function CreateSketchCurvesPath(pathSketchNames As String()) As Path
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each pathSketchName In pathSketchNames
Dim oPathSketch As Sketch = oCompDef.Sketches.Item(pathSketchName)
Dim oSketchPaths As Path = oFeats.CreatePath(oPathSketch.SketchLines(1))
For Each oPathEntity In oSketchPaths
Dim oSkEntity As SketchEntity
oSkEntity = oPathEntity.SketchEntity
Call oColl.Add(oSkEntity)
Next
Next
Dim oPath As Path = oFeats.CreateSpecifiedPath(oColl)
Return oPath
End Function
Function FeatureExists(featureName As String) As Boolean
For Each oFeat In oFeats
If oFeat.Name = featureName Then Return True
Next
Return False
End Function
End Class
Solved! Go to Solution.
Solved by cidhelp. Go to Solution.
Hello @KenPalAlt ,
you created a SweepDefinition-Object, not a SolidSweepDefinition. You have to edit this SweepDefinition. Also the logger needs a string-argument.
See my edits:
Thanks, works great!
Posting the corrected code in case someone finds this later:
Class Sweep
Dim oDoc As PartDocument
Dim oCompDef As ComponentDefinition
Dim oFeats As PartFeatures
Dim oSweepFeats As SweepFeatures
Sub Main
oDoc = ThisDoc.Document
oCompDef = oDoc.ComponentDefinition
oFeats = oCompDef.Features
oSweepFeats = oFeats.SweepFeatures
If FeatureExists("MySweep") Then oFeats("MySweep").Delete
Call MakeNewSweep("MySweep", "ProfileSketch", {"PathSketch1", "PathSketch2"})
Call UpdateSweep("MySweep", "ProfileSketch", {"PathSketch1", "PathSketch2", "PathSketch3"})
End Sub
Sub MakeNewSweep(sweepName As String, profileSketchName As String, pathSketchNames As String())
Dim oProfileSketch As Sketch = oCompDef.Sketches.Item(profileSketchName)
Dim oProfile As Profile = oProfileSketch.Profiles.AddForSolid
Dim oPath As Path = CreateSketchCurvesPath(pathSketchNames)
Dim oSweep As SweepFeature = oCompDef.Features.SweepFeatures.AddUsingPath(oProfile, oPath, kJoinOperation)
oSweep.Name = sweepName
End Sub
Sub UpdateSweep(sweepName As String, profileSketchName As String, pathSketchNames As String())
Dim oProfileSketch As Sketch = oCompDef.Sketches.Item(profileSketchName)
Dim oProfile As Profile = oProfileSketch.Profiles.AddForSolid
Dim oPath As Path = CreateSketchCurvesPath(pathSketchNames)
Dim oSweepFeat As SweepFeature = oSweepFeats(sweepName)
Dim oSweepDef As SweepDefinition = oSweepFeat.Definition
oSweepDef.Path = oPath
End Sub
Function CreateSketchCurvesPath(pathSketchNames As String()) As Path
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each pathSketchName In pathSketchNames
Dim oPathSketch As Sketch = oCompDef.Sketches.Item(pathSketchName)
Dim oSketchPaths As Path = oFeats.CreatePath(oPathSketch.SketchLines(1))
For Each oPathEntity In oSketchPaths
Dim oSkEntity As SketchEntity
oSkEntity = oPathEntity.SketchEntity
Call oColl.Add(oSkEntity)
Next
Next
Dim oPath As Path = oFeats.CreateSpecifiedPath(oColl)
Return oPath
End Function
Function FeatureExists(featureName As String) As Boolean
For Each oFeat In oFeats
If oFeat.Name = featureName Then Return True
Next
Return False
End Function
End Class
Can't find what you're looking for? Ask the community or share your knowledge.