Code upgrade: Include layer change of leader text

Code upgrade: Include layer change of leader text

Anonymous
Not applicable
292 Views
2 Replies
Message 1 of 3

Code upgrade: Include layer change of leader text

Anonymous
Not applicable

What the code does right now:

- It "Catches" a leader text, if it has a $ in front or another symbol of my choosing. It then changes the leader text to: Filename-XXX1 (next following number)

 

 

What I would like to include in this code is:

- That not only does it renumber the leaders with $ in front, but it also changes the default layer of the leader to a certain layer. In this case, the layer name is: TAG Number

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim Filename As String = Nothing
Filename=System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
Dim i As Integer =1
For Each oLeaderNote As LeaderNote In oDoc.ActiveSheet.DrawingNotes.LeaderNotes
oValue = oLeaderNote.Text
If oValue.StartsWith("$") Then
Dim no As String	
If i < 10 Then
	no = "0000" & i 
	End If
If i > 10 And i < 100 Then
	no = "000" & i
End If
If i > 100 And i < 1000 Then 
	no = "00" & i
	End If
If i > 1000 And i < 10000 Then 
	no = "0" & i
	End If	
oLeaderNote.Text = ("$" & Filename & "-"& no )
i=i+1
End If	
Next 
0 Likes
293 Views
2 Replies
Replies (2)
Message 2 of 3

HermJan.Otterman
Advisor
Advisor

Hello,

 

Here is a piece of code from one of my projects, to chnge the layer:

 

Dim drawcurves As DrawingCurvesEnumerator
                drawcurves = oDrawView.DrawingCurves(SelectedComponent)
 
                ' Create an empty collection.
                Dim objColl As ObjectCollection
                objColl = _inventorApplication.TransientObjects.CreateObjectCollection()
 
                ' Add the curve segments to the collection.
                Dim drawCurve As DrawingCurve
                For Each drawCurve In drawcurves
                    Dim segment As DrawingCurveSegment
                    For Each segment In drawCurve.Segments
                        objColl.Add(segment)
                    Next
                Next
 
                Dim oLayer As Layer = oDrawView.Parent.Parent.StylesManager.layers.Item(layerName)
 
                ' Change the layer of all of the segments.
                oDrawView.Parent.ChangeLayer(objColl, oLayer)

 instead of drawingcurves, you can put your leader, put it in the object collection, and then change the layer

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 3

Anonymous
Not applicable

My coding abilities are in the "early stages" 🙂

 

Could anyone give an example how this would look in my case and how I would incorporate this into my current code?

0 Likes