Placing custom leaders on parts in drawing view

Placing custom leaders on parts in drawing view

vjekoslav.vrbljanin
Participant Participant
192 Views
1 Reply
Message 1 of 2

Placing custom leaders on parts in drawing view

vjekoslav.vrbljanin
Participant
Participant

 

Hello, 

 

I have this ilogic code that places each individual part from the assembly on a new sheet in a drawing. In addition to that it places a text with some custom properties for that part.

I was wondering if there is a possibility to alter the code so that instead of a text there could be placed a custom leader that reads the same custom properties, aka something like an autoballon but with a custom leader.

 

This is the logic that I used:

'Determine if the file is an assembly or not and exit if this is only a Part
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
    MsgBox("This rule is for assembly documents",, "iLogic")
    Exit Sub
End If

'Define the necessary document variables
Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition

'Obtain the BOM and ensure the "Parts Only" BOM is enabled
Dim oBOM As BOM = oAssyCompDef.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts only")

Dim drawing As DrawingDocument ' Declare the drawing document variable

' Loop through each open document to find the drawing document
For Each doc As Document In ThisApplication.Documents
    If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        drawing = doc ' Set the drawing document variable
        Exit For ' Exit the loop once the drawing document is found
    End If
Next

If drawing Is Nothing Then
    MsgBox("No drawing document found", MsgBoxStyle.Exclamation, "iLogic")
    Exit Sub
End If

' Create a new sheet in the drawing document
Dim newSheet As Sheet = drawing.Sheets.Add()

Dim XPos As String
Dim YPos As String
XPos = 65
YPos = 30

'Cycle through each row of the "Parts Only" BOMView
For Each oBOMRow As BOMRow In oBOMView.BOMRows
    Dim occ As ComponentOccurrence = oBOMRow.ComponentOccurrences.Item(1)
    Dim name = occ.Name
	Dim Area As String 
	Dim oPoint As Point2d
	oPoint = ThisApplication.TransientGeometry.CreatePoint2d(XPos+1, YPos-2)
	
	oOne = "Item Number: " & iProperties.Value(oBOMRow.ComponentOccurrences.Item(1).Name, "Custom", "Item Number")
	oTwo = "Quantity: " & iProperties.Value(oBOMRow.ComponentOccurrences.Item(1).Name, "Custom", "Item qt")
	oFour = "Material: " & iProperties.MaterialOfComponent(oBOMRow.ComponentOccurrences.Item(1).Name)
	oThree = "Mass: " & Round(iProperties.MassOfComponent(oBOMRow.ComponentOccurrences.Item(1).Name), 2) & " kg"
	oFive = "Area: " & iProperties.Value(oBOMRow.ComponentOccurrences.Item(1).Name, "Custom", "Area") & "mm˘2"

    Try
        Dim refDoc = occ.Definition.Document
        Dim insertPoint = ThisApplication.TransientGeometry.CreatePoint2d(XPos, YPos)
        Dim orientation = ViewOrientationTypeEnum.kFrontViewOrientation
        Dim scale = 1/10
        Dim viewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle

        ' Add drawing view to the new sheet
        newSheet.DrawingViews.AddBaseView(refDoc, insertPoint, scale, orientation, viewStyle)
		strText = oOne & vbLf & oTwo & vbLf & oThree & vbLf & oFour & vbLf & oFive
		
		oGeneralNote = newSheet.DrawingNotes.GeneralNotes.AddFitted(oPoint, strText)
        
        ' Update position for the next view
		
        XPos = XPos + 12
	If XPos > 150 Then
		YPos = YPos - 10
		XPos = 65
	End If
	Catch ex As Exception
        Logger.Info("Cannot create drawing view")
    End Try
Next

 

 

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

A.Acheson
Mentor
Mentor

Hi @vjekoslav.vrbljanin 

This kind of automation can get fairly difficult depending on your expertise. If you want to continue down this route the two things you need to look on this forum for are to place a leader and formatted text.

 

For placing a leader you first need to work out where your placing it known as the intent. This will be the position on a drawing Curve you want the leader to be attached. This can be very diffiult process as when you place this manually the user decides where to put it based on there own visual style so it can be very random or in a known pattern. 

 

Here is a helpful article that does both placing a leader and works with parameter formatted text. The rule is written in VBA so you will need to convert to VB.NET for the ilogic environment.

 

For formatted text here is a link to the xml tags that make up the text. I would use this as a guide bit would probably stop short of trying to create the tags manually. There is an easier way to do so by manully placing your leader and your formatted text and then reading the xml tag from the leader.formattedtext you just placed. See help page here for syntax

Syntax

LeaderNote.FormattedText() As String

 

If you need any further help please post the modified code your working with and ask questions to understand a method etc.

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes