Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change line properties for surface bodies

2 REPLIES 2
Reply
Message 1 of 3
HogueOne
170 Views, 2 Replies

Change line properties for surface bodies

Hello!

 

I'm currently changing properties for all surface bodies manually to this:

HogueOne_0-1726758444313.png


I'm trying to achieve this programmatically instead. I'm starting with this code to target my surface bodies:

Sub Main()
    Dim oDoc As DrawingDocument = ThisDrawing.Document
    Dim oSheet As Sheet = oDoc.ActiveSheet
    Dim surfaceBodyCount As Integer = 0
    Dim surfaceBodyNames As New List(Of String)
    
    ' Loop through all drawing views on the active sheet
    For Each oView As DrawingView In oSheet.DrawingViews
        ' Check if the view's model is a part document
        If TypeOf oView.ReferencedDocumentDescriptor.ReferencedDocument Is PartDocument Then
            Dim partDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            ' Count visible surface bodies and get their names in the part
            Dim result = CountAndNameVisibleSurfaceBodiesInPart(partDoc)
            surfaceBodyCount += result.Item1
            surfaceBodyNames.AddRange(result.Item2)
        End If
    Next
    
    ' Prepare the result message
    Dim resultMessage As String = "Number of visible surface bodies found: " & surfaceBodyCount.ToString() & vbNewLine & vbNewLine
    resultMessage &= "Names of visible surface bodies:" & vbNewLine
    For Each name In surfaceBodyNames
        resultMessage &= "- " & name & vbNewLine
    Next
    
    ' Display the result in a message box
    MessageBox.Show(resultMessage, "Visible Surface Body Count and Names")
End Sub

Function CountAndNameVisibleSurfaceBodiesInPart(partDoc As PartDocument) As Tuple(Of Integer, List(Of String))
    Dim count As Integer = 0
    Dim names As New List(Of String)
    
    ' Loop through all work surfaces in the part
    For Each oWorkSurface As WorkSurface In partDoc.ComponentDefinition.WorkSurfaces
        ' Check if the work surface is visible
        If oWorkSurface.Visible Then
            ' Add the number of surface bodies in this visible work surface
            count += oWorkSurface.SurfaceBodies.Count
            
            ' Add the names of the surface bodies
            For Each surfaceBody As SurfaceBody In oWorkSurface.SurfaceBodies
                names.Add(SurfaceBody.Name)
            Next
        End If
    Next
    
    Return New Tuple(Of Integer, List(Of String))(count, names)
End Function


It simply counts the visible ones on the drawing. but now i need to change the line type and color. I think this syntax might be useful, but I can't seem to employ it properly:

LineTypeEnum Enumerator
Description
Enum indicating various color source types.
Methods
Name Value Description
kChainLineType 37644 Chain line style.

CurveGraphics.LineType Property
Parent Object: CurveGraphics
Description
Property that gets and sets the line type override. Setting the property to kDefaultLineType restores the default line type. If the property returns kCustomLineType, the GetCustomLineType method can be used to get further details about the line type.

Syntax
CurveGraphics.LineType() As LineTypeEnum

CurveGraphics.Color Property
Parent Object: CurveGraphics
Description
Gets and sets color associated with this primitive.

Syntax
CurveGraphics.Color() As Color


Color Object

Description
The Color object provides access to all of the components defining a color.
Methods
Name Description
GetColor Method that gets the color components of the Color object.
SetColor Method that sets the color components of the Color object.
Properties
Name Description
Blue Specifies the blue component of the color.
ColorSourceType Gets and sets the color source type.
Green Specifies the green component of the color.
Opacity Specifies the opacity value.
Red Specifies the red component of the color.
Type Returns an ObjectTypeEnum indicating this object's type.

please help! 🙂



Labels (7)
2 REPLIES 2
Message 2 of 3
J_Pfeifer_
in reply to: HogueOne

I didn't write up everything but I was also curious how to get to the line type and line weight properties for a drawing view. See my inserted code and the pictures showing the output. 

 

The key is going to be, targeting the correct drawing view. Checking to see if that surfacebody is in the view. Then getting the lines associated with that body to edit the drawing curve properties. 

 

Sub main()
	
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	
	Dim oSheet1 As Sheet = oDoc.Sheets.Item(2)
	
	For Each oView As DrawingView In oSheet1.DrawingViews
		If oView IsNot Nothing Then 
			For Each oLine As DrawingCurve In oView.DrawingCurves
				oLine.LineWeight = .1
				oLine.LineType = LineTypeEnum.kContinuousLineType
			Next
		End If 
	Next
	
End Sub

 

You're really just trying to get to the drawing curves or all the drawing curves associated then changing their properties. Not sure exactly how or if you can check if a drawing curve from a surfacebody are associated to each other, but this should point in the correct general direction. 

 

I looked into trying to specify the entire body object the way you described, I do not see access to those properties until you get down to the drawing curve level.

 

Digging into the graphics objects, they seem to be lower level API items, that is if you wanted to do things with the actual graphics/render processor from the engine. 

Message 3 of 3
Andrii_Humeniuk
in reply to: HogueOne

Hi @HogueOne . Please try this iLogic code. I hope this is what you need.

 

Public Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
	Dim newTM As Transaction = oInvApp.TransactionManager.StartTransaction(oDDoc, "ChangeCurvesColor")
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	For Each oView As DrawingView In oSheet.DrawingViews
		Dim oPDoc As PartDocument = TryCast(oView.ReferencedDocumentDescriptor.ReferencedDocument, PartDocument)
		If oPDoc Is Nothing Then Continue For
		For Each oSrf As WorkSurface In oPDoc.ComponentDefinition.WorkSurfaces
			Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oSrf)
			For Each oCurve As DrawingCurve In oCurves
				On Error Resume Next
				With oCurve
					.Color = oInvApp.TransientObjects.CreateColor(255, 0, 0) 'Red
					.LineType = LineTypeEnum.kChainLineType
					.LineWeight = 0.0254 ' 0.001 in
				End With
			Next
		Next
	Next
	newTM.End()
End Sub

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report