- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I found the code for VBA on the forum
I wanted to modify this code for iLogic, but I can't do it at all, I'm constantly getting bugs or nothing.
Original Code for VBA is OK
Sub ChangePartColor() Dim oDoc As DrawingDocument, partStr As String If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then Call MsgBox("This macro only works on drawing documents.") Exit Sub End If Set oDoc = ThisApplication.ActiveDocument partStr = InputBox("Part to color:", "Prompt") Dim oTrans As Transaction, i, j, k, c Dim ViewCurves As DrawingCurvesEnumerator, refAssyDef As ComponentDefinition, oColor As color Set oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'RGB Set oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Colorize [PART]") For Each i In oDoc.Sheets For Each j In i.DrawingViews If j.ReferencedDocumentDescriptor.ReferencedDocumentType = kPresentationDocumentObject Then Set refAssyDef = j.ReferencedDocumentDescriptor.ReferencedDocument.ReferencedDocuments(1).ComponentDefinition ElseIf j.ReferencedFile.DocumentType = kAssemblyDocumentObject Then Set refAssyDef = j.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition End If For Each k In refAssyDef.Occurrences If k.name Like partStr & ":*" Then Set ViewCurves = j.DrawingCurves(k) For Each c In ViewCurves c.color = oColor Next End If Next Next Next oTrans.End End Sub
That's how I changed it, but it still doesn't work for me. I think the error is on this line = Dim oTrans As Transaction
iLogic = doesn't work
Sub Main() Dim oDoc As DrawingDocument Dim partStr As String If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then Call MsgBox("This macro only works on drawing documents.") Exit Sub End If oDoc = ThisApplication.ActiveDocument partStr = InputBox("Part to color:", "Prompt") Dim oTrans As Transaction Dim ViewCurves As DrawingCurvesEnumerator Dim refAssyDef As ComponentDefinition Dim oColor As Color oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0) 'RGB oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Colorize [PART]") For Each i In oDoc.Sheets For Each j In i.DrawingViews If j.ReferencedDocumentDescriptor.ReferencedDocumentType = kPresentationDocumentObject Then refAssyDef = j.ReferencedDocumentDescriptor.ReferencedDocument.ReferencedDocuments(1).ComponentDefinition ElseIf j.ReferencedFile.DocumentType = kAssemblyDocumentObject Then refAssyDef = j.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition End If For Each k In refAssyDef.Occurrences If k.Name Like partStr & ":*" Then ViewCurves = j.DrawingCurves(k) For Each c In ViewCurves c.Color = oColor Next End If Next Next Next oTrans.End End Sub
Solved! Go to Solution.
Link copied