Change line properties for surface bodies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I'm currently changing properties for all surface bodies manually to this:
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! 🙂