- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How to se DrawCurve to ByLayer?
Sub SetDrawingCurvesLayer(ByVal app As Inventor.Application)
If (MainLayer Is Nothing) Then Return
If (drawCurves Is Nothing) Then Return
' Create empty collections for curves on different layers
Dim objColl As ObjectCollection = app.TransientObjects.CreateObjectCollection()
Dim hiddenColl As ObjectCollection = Nothing
If (HiddenLayer IsNot Nothing) Then
hiddenColl = app.TransientObjects.CreateObjectCollection()
End If
' Iterate through each drawing curve
For Each drawCurve As DrawingCurve In drawCurves
If (drawCurve.Segments Is Nothing) Then Continue For
Dim oColor As Color
drawCurve.Color = oColor
For Each segment As DrawingCurveSegment In drawCurve.Segments
If (segment.HiddenLine) Then
If (hiddenColl IsNot Nothing) Then
hiddenColl.Add(segment)
End If
Else
' Add the segment to the collection for visible curves
objColl.Add(segment)
End If
Next
Next
' Change the layer of visible curves
If (objColl.Count > 0) Then
drawView.Parent.ChangeLayer(objColl, MainLayer)
End If
' Change the layer of hidden curves
If (hiddenColl IsNot Nothing AndAlso hiddenColl.Count > 0) Then
drawView.Parent.ChangeLayer(hiddenColl, HiddenLayer)
End If
End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Leonardo_Czuy. Most of that code looks OK, but this is obviously not the entire code, so there are some things we can not know about this. This Sub routine only has one input parameter, yet it is using several variables within it (such as MainLayer, drawCurves, & HiddenLayer) that are neither passed into it, nor created within it, so we don't know if those other variables have been declared, if they have been assigned values, or what Type of object they represent. There is an odd couple of lines were you create a variable (oColor) for a Color object, do not set a value to it, then set that oColor variable as the value of 'drawCurve.Color. I am not sure what you were trying to do there, but it does not look correct right now. I assume that the 'drawCurves' variable represents a DrawingCurvesEnumberator, and that the 'MainLayer' & 'HiddenLayer' variables represent Layer objects, but if those variables are not declared at a 'higher level' within the overall code, then I do not know if this Sub routine will recognize them, or be able to use that as you intended. Also, if those Layers are Layers exist within the drawing being currently processed or not. If not, you may need to either copy those layers from a library to the drawing document, or create those layers within the drawing document directly, before you can use them.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@WCrihfield
Follow all code
Sub Main
drawDoc = TryCast(ThisDoc.Document, DrawingDocument)
If (drawDoc Is Nothing) Then
MessageBox.Show("Esta regra só pode ser executada em um desenho,", "iLogic")
Return
End If
view = InputBox("Digite o Indentificador da Vista:", "iLogic")
If view = "" Then
MessageBox.Show("Necessário fornecer Indentificador da Vista", "iLogic")
Return
End If
peca = InputBox("Digite o código da Peça:", "iLogic")
If peca = "" Then
MessageBox.Show("Necessário fornecer o código de uma peça", "iLogic")
Return
End If
LookForView()
End Sub
Private drawDoc As DrawingDocument
Private modelDoc As Document
Private peca As String
Private view As String
Public Sub LookForView()
' Process the occurrences, wrapping it in a transaction so the
' entire process can be undone with a single undo operation.
Dim trans As Transaction
trans = ThisApplication.TransactionManager.StartTransaction(drawDoc, "Drawing Layers to Existing")
Try
For Each dSheet As Sheet In drawDoc.Sheets
For Each drawView As DrawingView In dSheet.DrawingViews
If (drawView.ViewType = DrawingViewTypeEnum.kDraftDrawingViewType) Then Continue For
If drawView.Name.ToString() = view
Dim docDesc As DocumentDescriptor
docDesc = drawView.ReferencedDocumentDescriptor
If (docDesc Is Nothing) Then Continue For
If (docDesc.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
If (docDesc.ReferencedDocument Is Nothing) Then Continue For
Dim asmDef As AssemblyComponentDefinition
Dim assemDoc As AssemblyDocument = TryCast(docDesc.ReferencedDocument, AssemblyDocument)
If (assemDoc) Is Nothing Then Continue For
asmDef = assemDoc.ComponentDefinition
If (asmDef Is Nothing) Then Continue For
If (asmDef.Occurrences Is Nothing) Then Continue For
ProcessOccurrences(drawView, asmDef.Occurrences)
ElseIf (docDesc.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
Dim partDoc As PartDocument = TryCast(docDesc.ReferencedDocument, PartDocument)
If (partDoc Is Nothing) Then Continue For
'ProcessPart(drawView, partDoc)
End If
End If
Next
Next
Catch
trans.Abort()
Return
End Try
trans.End()
End Sub
Sub ProcessOccurrences(ByVal drawView As DrawingView, ByVal Occurrences As ComponentOccurrences)
' Iterate through the current collection of occurrences.
Dim occ As ComponentOccurrence
For Each occ In Occurrences
If (occ.Suppressed) Then Continue For
If (occ.Definition Is Nothing) Then Continue For
If (occ.ReferencedDocumentDescriptor Is Nothing) Then Continue For
If (occ.ReferencedDocumentDescriptor.ReferenceMissing) Then Continue For
Dim parentComponent As ComponentOccurrence = occ.ParentOccurrence
Dim FileName As String
If parentComponent IsNot Nothing
FileName = parentComponent.Name
Dim partes As String() = FileName.Split(":"c)
FileName = partes(0).Trim()
End If
If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
' ** It's a part, so get the material.
if FileName <> peca Then Continue For
Dim partDoc As PartDocument = TryCast(occ.Definition.Document, PartDocument)
If (partDoc Is Nothing) Then Continue For
' Get all of the curves associated with this occurrence.
Dim drawCurves As DrawingCurvesEnumerator = Nothing
Try
drawCurves = drawView.DrawingCurves(occ)
Catch
drawCurves = Nothing
End Try
If (drawCurves IsNot Nothing) Then
Dim matLayers As New MaterialLayers(drawDoc, partDoc, drawView, drawCurves)
matLayers.GetOrCreateMainLayer()
matLayers.SetDrawingCurvesLayer(ThisApplication)
End If
Else
' It's an assembly, so process its contents.
Call ProcessOccurrences(drawView, occ.SubOccurrences)
End If
Next
End Sub
Class MaterialLayers
Public MainLayer As Layer
Public HiddenLayer As Layer
' The layer for:
' Solid lines in a plan or projected view: MaterialName
' Hidden lines in a plan or projected view: MaterialName-Hidden
' Solid lines in any other view: MaterialName-View
' Hidden lines in any other view: MaterialName-View-Hidden
Private drawDoc As DrawingDocument
Private partDoc As PartDocument
Private drawView As DrawingView
Private drawCurves As DrawingCurvesEnumerator
Public Sub New(ByRef drawDoc As DrawingDocument, ByVal partDoc As PartDocument, ByVal drawView As DrawingView, ByVal drawCurves As DrawingCurvesEnumerator)
Me.drawDoc = drawDoc
Me.partDoc = partDoc
Me.drawView = drawView
Me.drawCurves = drawCurves
End Sub
Sub GetOrCreateMainLayer()
Dim layers As LayersEnumerator = drawDoc.StylesManager.Layers
Try
ContorniLayer = layers.Item("CONTORNI")
Catch
End Try
Try
NacosteLayer = layers.Item("NASCOSTE")
Catch
End Try
MainLayer = ContorniLayer
HiddenLayer = NacosteLayer
End Sub
Sub SetDrawingCurvesLayer(ByVal app As Inventor.Application)
If (MainLayer Is Nothing) Then Return
If (drawCurves Is Nothing) Then Return
' Create empty collections for curves on different layers
Dim objColl As ObjectCollection = app.TransientObjects.CreateObjectCollection()
Dim hiddenColl As ObjectCollection = Nothing
If (HiddenLayer IsNot Nothing) Then
hiddenColl = app.TransientObjects.CreateObjectCollection()
End If
' Iterate through each drawing curve
For Each drawCurve As DrawingCurve In drawCurves
If (drawCurve.Segments Is Nothing) Then Continue For
drawCurve.Color = MainLayer.Color
For Each segment As DrawingCurveSegment In drawCurve.Segments
If (segment.HiddenLine) Then
If (hiddenColl IsNot Nothing) Then
hiddenColl.Add(segment)
End If
Else
' Add the segment to the collection for visible curves
objColl.Add(segment)
End If
Next
Next
' Change the layer of visible curves
If (objColl.Count > 0) Then
drawView.Parent.ChangeLayer(objColl, MainLayer)
End If
' Change the layer of hidden curves
If (hiddenColl IsNot Nothing AndAlso hiddenColl.Count > 0) Then
drawView.Parent.ChangeLayer(hiddenColl, HiddenLayer)
End If
End Sub
End Class