Redefining/Adding LoftRails to existing lofts

Redefining/Adding LoftRails to existing lofts

nick.seman
Advocate Advocate
170 Views
1 Reply
Message 1 of 2

Redefining/Adding LoftRails to existing lofts

nick.seman
Advocate
Advocate

Hello:

 

I have a part file containing numerous lofts.  I (am trying) to write a rule that will look at each loft in the part file and if it ends in a "-1" add a rail (3d sketch named "3D Sketch Road").  The 3D sketch "3D Sketch Road" contains a single continuous projected edge (lines/curves).

 

This is the code as it is now:

 

Dim doc As PartDocument = ThisDoc.Document
Dim oFeatures As PartFeatures = doc.ComponentDefinition.Features

Dim fName As String
Dim rOne As String

Dim targetSketchName As String = "3D Sketch Road"

Dim railSketch As Sketch3D = Nothing

For Each sketch As Sketch3D In doc.ComponentDefinition.Sketches3D
	If Sketch.Name = targetSketchName Then
		railSketch = Sketch
	End If
Next

For Each Feature As Object In oFeatures

	fName = Feature.Name
	rOne = Right(fName, 2)
	If rOne = "-1" Then
		If Feature.Type = ObjectTypeEnum.kLoftFeatureObject Then
			Dim oloftFeature As LoftFeature = Feature
			
			MsgBox(fName)
			MsgBox(railSketch.Name)

			Dim oRail As Profile3D
			oRail = railSketch.Profiles3D.AddOpen
			oloftFeature.Definition.LoftRails.Add(oRail)
			
		End If
	End If
Next

It ran initially but now I am getting an unspecified error on the "oloftFeature.Definition.LoftRails.Add(oRail)" line.

 

The two message boxes display the appropriate selections for the selected feature and sketch.

 

I would appreciate any ideas that might help me get it straightened out.

 

Thanks;

Nick

0 Likes
171 Views
1 Reply
Reply (1)
Message 2 of 2

nick.seman
Advocate
Advocate

I modified the code which now works in 2 out of 3 cases.

 

(1) If the lofts have a selected rail the code deletes it and reselects the rail specified in the code.  The snip below shows what the loft dialog box would look like before running the rule.

 

nickseman_0-1706195863602.png

 

(2) If the lofts do not have any selected rail then it adds the rail specified in the code.  The snip below shows what the loft dialog box would look like before running the rule.

 

nickseman_1-1706195898179.png

 

(3)   The Loft Rail is subject to changes in geometry.  In some cases, the geometry changing will make the lofts "lose" their association to the selected Rail (see how the dialog box below differs from that in number 2 above).  In this case the code errors out "Unspecified Error" on >> xRail.Delete() <<.  If I do a xRail.Count it shows 1 rail but I cannot delete it.

 

nickseman_2-1706198145410.png

 

If I rem out the xRail.Delete() line, the code then errors out "Unspecified Error" on the >> oloftFeature.Definition.LoftRails.Add(oRail)  << line, i.e. I cannot add the correct rail either.

 

Any ideas ?

 

Thanks Nick

 

Dim doc As PartDocument = ThisDoc.Document
Dim oFeatures As PartFeatures = doc.ComponentDefinition.Features

Dim fName As String
Dim rOne As String
Dim targetSketchName As String = "3D Sketch Road"

Dim railSketch As Sketch3D = Nothing

For Each sketch As Sketch3D In doc.ComponentDefinition.Sketches3D
	If Sketch.Name = targetSketchName Then
		railSketch = Sketch
	End If
Next

For Each Feature As Object In oFeatures

	fName = Feature.Name
	rOne = Right(fName, 2)
	If rOne = "-1" Or rOne = "1u" Then
		If Feature.Type = ObjectTypeEnum.kLoftFeatureObject Then
			Dim oloftFeature As LoftFeature = Feature
			
			Dim oRail As Profile3D
			
			Dim xRails As LoftRails
			xRails = oloftFeature.Definition.LoftRails
			
			Dim xRail As LoftRail
			
			For Each xRail In xRails
				xRail = xRails.Item(1)
				xRail.Delete()			
			Next
			
			oRail = railSketch.Profiles3D.AddOpen
			oloftFeature.Definition.LoftRails.Add(oRail)
			
		End If
	End If
Next

 

0 Likes