- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to change TitleBlock, Border and symbol and in many drawings.
I don´t want to copy yhe symbol in to all the drawings. I like to use a symbol from the templates, or symbol library.
It would be wonderful if it would be possible to change more then one symbol in the same rule.
I can change the TitleBlock and Border, but the rule don´t find the symbol.
What is the different of:
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
and
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document?
This is my code (that only work if the symbol exist in the drawing):
ThisDrawing.ResourceFileName = "R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw"
ThisDrawing.KeepExtraResources = False
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument
'Dim oDrawDoc = ThisApplication.ActiveDocument
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols
Dim oCurrentNumber As Sheet
oCurrentNumber = oDoc.ActiveSheet
Dim oSheet As Sheet
For Each oSheet In oDoc.Sheets ' Iterate through the sheets, and delete the title blocks and symbols
oSheet.Activate
For Each oSymbol In oSheet.SketchedSymbols 'remove existing sketched symbols named Text Secondary steel
If oSymbol.Definition.Name = "General3" Or oSymbol.Definition.Name = "General Drawing1" _
Or oSymbol.Definition.Name = "General" Or oSymbol.Definition.Name = "General2" Then
oSymbol.Delete
End If
Next
'============ Lägger in rätt symbol på rätt ställe
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document ' Set a reference to the drawing document. This assumes a drawing document is active.
'Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSketchedSymbolDef As SketchedSymbolDefinition _
= oDrawDoc.SketchedSymbolDefinitions.Item("General3")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 'create insertion point, coordinates - in cm !
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(83.6, 28) '(74, 52)
Dim oSketchedSymbol As SketchedSymbol _
= oSheet.SketchedSymbols.Add( _ ' Add an instance of the sketched symbol definition to the sheet.
oSketchedSymbolDef, _ ' Rotate angle = 0 radians,
oInsertionPoint, _ ' scale = 1 when adding
0, 1, Nothing) ' no prompt text
'============================================================== Put in the Symbol "General3" DOES NOT WORK !!
Dim oSketchedSymbolDef2 As SketchedSymbolDefinition _
= oDrawDoc.SketchedSymbolDefinitions.Item("General3")
Dim oTG2 As TransientGeometry = ThisApplication.TransientGeometry 'create insertion point, coordinates - in cm !
Dim oInsertionPoint2 As Point2d = oTG.CreatePoint2d(83.6, 28)
Dim oSketchedSymbol2 As SketchedSymbol _
= oSheet.SketchedSymbols.Add( _ ' Add an instance of the sketched symbol definition to the sheet.
oSketchedSymbolDef, _ ' Rotate angle = 0 radians,
oInsertionPoint, _ ' scale = 1 when adding
0, 1, Nothing) ' no prompt text
Try
oSheet.TitleBlock.Delete
Catch 'catch error if no border found
End Try
ActiveSheet.TitleBlock = "Boden rithuvud2" 'Byter rithuvudet till Boden rithuvud 2 från templatesen.
Try
oSheet.Border.Delete
Catch 'catch error if no border found
End Try
ActiveSheet.Border = "Boden2" 'set new border
Next
Try '============== Sparar ritningen som dwg. Med samma namn och på samma plats.
ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & (".dwg") , True)
Catch
MessageBox.Show("Det gick tyvärr inte att spara filen som dwg." & vbLf & _
"Vill ni vara snäll och kontrollera att dwg-filen är stängd?", "Problem med dwg-filen")
End Try
Solved! Go to Solution.