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: 

Importing drawing resources

4 REPLIES 4
Reply
Message 1 of 5
robmatthews
839 Views, 4 Replies

Importing drawing resources

Inventor 9 (not 2009)...

I have an old drawing, and I want to replace the Title block with that from our newer template.


Private Sub BorderTitleBlock()
Dim oIDWDoc As DrawingDocument
Set oIDWDoc = ThisApplication.ActiveDocument
Dim oSourceFile As DrawingDocument
Dim oSheet As Sheet
Dim oTitleBlock
Dim SourceFileName As String
Dim ActiveTitleBlockName As String
Dim oTBDef As TitleBlockDefinition
Dim bFound As Boolean

For Each oSheet In oIDWDoc.Sheets
Set oTitleBlock = oSheet.TitleBlock
ActiveTitleBlockName = oTitleBlock.Definition.Name
If ActiveTitleBlockName <> "HCTitleBlock Metric" Then
oTitleBlock.Delete
For Each oTBDef In oIDWDoc.TitleBlockDefinitions
If oTBDef.Name = "HCTitleBlock Metric" Then
bFound = True
Set oTitleBlock = oSheet.AddTitleBlock(oIDWDoc.TitleBlockDefinitions.Item("HCTitleBlock Metric"))
Exit For
End If
Next
If Not bFound Then
SourceFileName = "\\brisbane-fs01\CAD_SERV\Inventor\Templates9\Standard.idw"
Set oSourceFile = ThisApplication.Documents.Open(SourceFileName, False)
oIDWDoc.TitleBlockDefinitions.Add (oSourceFile.TitleBlockDefinitions("HCTitleBlock Metric")) 'this is incorrect... What should i have here?
Set oTitleBlock = oSheet.AddTitleBlock("HCTitleBlock Metric")
oSourceFile.Close
Set oSourceFile = Nothing
End If
End If
Next
End Sub


If i just say :
Set oTitleBlock = oSheet.AddTitleBlock(oSourceFile.TitleBlockDefinitions("HCTitleBlock Metric")) then the correct titleblock is not added to the titleblock collection, and the text is formatted and placed incorrectly.

So how do "copy" drawing resources from one idw to another?
=============================================
This is my signature, not part of my post.
4 REPLIES 4
Message 2 of 5
robmatthews
in reply to: robmatthews

This also is not valid, although my thinking is that it is exactly what i want to do... Add a new (copied) titleblock to the TitleBlockDefinitions collection.

oIDWDoc.TitleBlockDefinitions.AddTitleBlock (oSourceFile.TitleBlockDefinitions("HCTitleBlock Metric"))

Is this at all possible? Or must I create a new (blank) titleblock using TitleBlockDefinitions.Add and then somehow incorporate all our functionality?
=============================================
This is my signature, not part of my post.
Message 3 of 5
Anonymous
in reply to: robmatthews

You first need to copy the definition over from the source document to the
target document. You can't use a definition from a different document.
Unfortunately for you, the API to copy titleblock definitions across
documents was also added in Inventor 10.

Sanjay-
Message 4 of 5
robmatthews
in reply to: robmatthews

Thank you for your response, Sanjay. That will stop me banging my head against the wall, trying to find the solution...

I guess that will be a manual operation then.

Cheers.
=============================================
This is my signature, not part of my post.
Message 5 of 5
harm.uenk
in reply to: robmatthews

For Inventor 2010:

 

Delete old resources:

Dim oDocument As DrawingDocument   

Dim oSheet As Sheet   

Dim oPane As BrowserPane   

Dim oDocumentNode As BrowserNode   

Dim oDrawingResourceNode As BrowserNode   

Dim oSheetFormatsNode As BrowserNode   

Dim oBordersNode As BrowserNode   

Dim oTitleBlocksNode As BrowserNode   

Dim oSBsNode As BrowserNode       

 

Set oDocument = ThisApplication.ActiveDocument    'Delete titleblock on sheet   

If Not oDocument.ActiveSheet.TitleBlock Is Nothing Then     

For Each oSheet In oDocument.Sheets           

oSheet.TitleBlock.Delete       

Next   

End If   

'Delete border on sheet   

If Not oDocument.ActiveSheet.Border Is Nothing

Then     

For Each oSheet In oDocument.Sheets           

oSheet.Border.Delete           

oSheet.AddDefaultBorder       

Next   

End If   

oDocument.BrowserPanes.Item("Model").Activate       

'Delete Drawing Resources   

Set oPane = oDocument.BrowserPanes.ActivePane   

Set oDocumentNode = oPane.TopNode   

Set oDrawingResourceNode = oDocumentNode.BrowserNodes.Item("Drawing Resources")    oDrawingResourceNode.DoSelect                   

'Delete Sheet Formats   

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

For Each oSheetFormatsNode In oSheetFormatsNode.BrowserNodes   

oSheetFormatsNode.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute   

Next
'Delete Borders   

Set oBordersNode = oDrawingResourceNode.BrowserNodes.Item("Borders")   

For Each oBordersNode In oBordersNode.BrowserNodes   

oBordersNode.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute   

Next
 'Delete Title Blocks   

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

For Each oTitleBlocksNode In oTitleBlocksNode.BrowserNodes   

oTitleBlocksNode.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute   

Next
'Delete Sketched Symbols   

Set oSBsNode = oDrawingResourceNode.BrowserNodes.Item("Sketched Symbols")   

For Each oSBsNode In oSBsNode.BrowserNodes   

oSBsNode.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute   

Next       

 

AddNewTitleblock

 

' Open the new drawing to copy the title block into.   

Dim oDocument As DrawingDocument   

Dim oSourceDocument As DrawingDocument   

Dim oSourceTitleBlockDef As TitleBlockDefinition   

Dim oNewTitleBlockDef As TitleBlockDefinition   

Dim oSPane As BrowserPane   

Dim aPane As BrowserPane   

Dim oSNode As BrowserNode   

Dim oSDRNode As BrowserNode   

Dim oSTitle As BrowserNode   

Dim aDocNode As BrowserNode   

Dim aDrResNode As BrowserNode   

Dim aTBNode As BrowserNode       

Dim oSheet As Sheet           

Set oDocument = ThisApplication.ActiveDocument   

Set oSourceDocument = ThisApplication.Documents.Add(kDrawingDocumentObject, "\\foo\Inventor2010\Templates\Standard_ISO.idw", True)   

Set oSourceTitleBlockDef = oSourceDocument.ActiveSheet.TitleBlock.Definition   

Set oSPane = oSourceDocument.BrowserPanes.Item("Model")   

Set oSNode = oSPane.TopNode   

Set oSDRNode = oSNode.BrowserNodes.Item("Drawing Resources")   

Set aPane = oDocument.BrowserPanes.ActivePane   

Set aDocNode = aPane.TopNode   

Set aDrResNode = aDocNode.BrowserNodes.Item("Drawing Resources")       

' Kopiëer Title Blocks   

oSourceDocument.Activate   

Set oSTitle = oSDRNode.BrowserNodes.Item("Title Blocks")   

oSTitle.EnsureVisible   

oSTitle.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd").Execute   

oDocument.Activate   

aDrResNode.DoSelect   

Set aTBNode = aDrResNode.BrowserNodes.Item("Title Blocks")   

aTBNode.EnsureVisible   

aTBNode.DoSelect    ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd").Execute       

' Kopiëer Sketched Symbols   

oSourceDocument.Activate   

Set oSTitle = oSDRNode.BrowserNodes.Item("Sketched Symbols")   

oSTitle.EnsureVisible   

oSTitle.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd").Execute   

oDocument.Activate   

aDrResNode.DoSelect   

Set aTBNode = aDrResNode.BrowserNodes.Item("Sketched Symbols")   

aTBNode.EnsureVisible   

aTBNode.DoSelect   

ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd").Execute        

 

oSourceDocument.Close       

 

' Get the new title block definition.   

'Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(oDocument)   

' Iterate through the sheets.   

For Each oSheet In oDocument.Sheets       

oSheet.Activate       

Call oSheet.AddTitleBlock("ISO")       

Next

 

Maybe there is a faster way?

 

Greetz Harm Uenk

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

Post to forums  

Autodesk Design & Make Report