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: 

IV2009 - Purge styles?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
310 Views, 4 Replies

IV2009 - Purge styles?

Is there an API command to purge styles from a drawing? I'm writing a drawing "cleaner" to get rid of unused borders, symbols, etc. I'd like to also purge styles if possible. TIA
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

The Style.Delete method is the equivalent of purge. It works only on local
(or locally modified) styles and fails for library styles.

Sanjay-
Message 3 of 5
amattos
in reply to: Anonymous

This may help you cleaning Drawing Resource up

Public Sub IDW_DelAllDrawingResources()

' If the active document is not a DRAWING , inform the user and stop the macro
msgPrm1 = " This Macro Only Works with Drawings Documents "
msgPrm2 = " Please open a Drawing "
msgTit = "Wrong Active Document Type"
Prm1 = Len(msgPrm1) + 4
Prm2 = Len(msgPrm2) + 4
Tit = Len(msgTit)
cmsgPrm2 = String((Prm1 - Prm2) / 2, Chr(32)) & msgPrm2
cmsgTit = String((Prm1 - Prm2) / 2, Chr(32)) & msgTit

'check if the active document is a drawing document
If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
' If iNSTR(1,
' MsgBox "The Active Document is a Template this macro will terminate", vbExclamation, "Wrong Active Document Type"

'End If

Else
MsgBox msgPrm1 & Chr(13) & Chr(13) & cmsgPrm2, vbExclamation, cmsgTit
End If



Dim oPane As BrowserPane
Set oPane = oDoc.BrowserPanes.ActivePane

Dim oDocNode As BrowserNode
Set oDocNode = oPane.TopNode

Dim oDrawingResourceNode As BrowserNode
Set oDrawingResourceNode = oDocNode.BrowserNodes.Item("Drawing Resources")

Dim oSheetFormatsNode As BrowserNode
Set oSheetFormatsNode = oDrawingResourceNode.BrowserNodes.Item("Sheet Formats")

Dim oBordersNode As BrowserNode
Set oBordersNode = oDrawingResourceNode.BrowserNodes.Item("Borders")

Dim oTitleBlocksNode As BrowserNode
Set oTitleBlocksNode = oDrawingResourceNode.BrowserNodes.Item("Title Blocks")

Dim oSketchedSymbolsNode As BrowserNode
Set oSketchedSymbolsNode = oDrawingResourceNode.BrowserNodes.Item("Sketched Symbols")

' Loop thru each resource node

oDrawingResourceNode.DoSelect
oDrawingResourceNode.EnsureVisible
oDrawingResourceNode.Expanded = True


Dim oSheetFormatNode As BrowserNode
For Each oSheetFormatNode In oSheetFormatsNode.BrowserNodes

' Select the node in the browser.
oSheetFormatNode.DoSelect
oSheetFormatNode.Expanded = True


' Execute the delete command.
'Debug.Print oSheetFormatNode.FullPath
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next

Dim oBorderNode As BrowserNode
For Each oBorderNode In oBordersNode.BrowserNodes

' Select the node in the browser.
oBorderNode.DoSelect
oBorderNode.Expanded = True

' Execute the delete command.
'Debug.Print oBorderNode.FullPath
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next

Dim oTitleBlockNode As BrowserNode
For Each oTitleBlockNode In oTitleBlocksNode.BrowserNodes

' Select the node in the browser.
oTitleBlockNode.DoSelect
oTitleBlockNode.Expanded = True

' Execute the delete command.
'Debug.Print oTitleBlockNode.FullPath
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next

Dim oSketchedSymbolNode As BrowserNode
For Each oSketchedSymbolNode In oSketchedSymbolsNode.BrowserNodes

' Select the node in the browser.
oSketchedSymbolNode.DoSelect
oSketchedSymbolNode.Expanded = True

' Execute the delete command.
'Debug.Print oSketchedSymbolNode.FullPath
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next

'oDoc.Save
End Sub
Message 4 of 5
Anonymous
in reply to: Anonymous

Thanks avmattos, below is the solution I came up with (note no ControlDefinitions.Execute method)

------------------------------------------------------------------



Public Sub DrawingCleanDrawingResources()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = GetActiveDrawing
If oDrawDoc Is Nothing Then Exit Sub

'get rid of sheet formats
Dim oSF As SheetFormat
For Each oSF In oDrawDoc.SheetFormats
oSF.Delete
Next oSF

'get rid of borders
Dim oBorderDef As BorderDefinition
For Each oBorderDef In oDrawDoc.BorderDefinitions

If Not oBorderDef.IsReferenced And Not oBorderDef.IsDefault Then
oBorderDef.Delete
End If

Next oBorderDef

'get rid of titleblocks
Dim oTBDef As TitleBlockDefinition
For Each oTBDef In oDrawDoc.TitleBlockDefinitions

If Not oTBDef.IsReferenced Then
oTBDef.Delete
End If

Next oTBDef

'get rid of symbols
Dim oSymbol As SketchedSymbolDefinition
For Each oSymbol In oDrawDoc.SketchedSymbolDefinitions

If Not oSymbol.IsReferenced Then
oSymbol.Delete
End If

Next oSymbol

End Sub




Public Function GetActiveDrawing() As DrawingDocument

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set GetActiveDrawing = ThisApplication.ActiveDocument
Else
MsgBox "Must have a drawing active", vbOKOnly, "Error"
End If

End Function
Message 5 of 5
amattos
in reply to: Anonymous

Josh,

Thanks for a lean way to do it. Good job. I did not try it yet but my guess is your code runs faster.

Regards,

Anderson Mattos

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report