Replace symbol from Template

Replace symbol from Template

autodeskpelinder
Enthusiast Enthusiast
2,066 Views
15 Replies
Message 1 of 16

Replace symbol from Template

autodeskpelinder
Enthusiast
Enthusiast

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

Johan Sweden
Accepted solutions (1)
2,067 Views
15 Replies
Replies (15)
Message 2 of 16

MechMachineMan
Advisor
Advisor

FTFY -- proper nesting with readability.

 

Now, what isn't working? is it throwing an error? 

 

Also, your code is currently trying to add general3 twice...

 

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

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 16

autodeskpelinder
Enthusiast
Enthusiast

The problem is that it does not replace the symbol if the symbol is not in the drawing.


Sorry I had the same symbol twice. I tried to place 2 different symbols on the drawing, but I failed.

 

I get this error:

Error in rule: Change symbol, in document: 14361.idw

Felaktig parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

See also the attached pictures.

Johan Sweden
0 Likes
Message 4 of 16

bradeneuropeArthur
Mentor
Mentor
Hi,
you can use "Drawing Resource Transfer Wizard" found in:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Autodesk Inventor 20##\Tools

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 16

autodeskpelinder
Enthusiast
Enthusiast
Hi!
No. I have tried that. But I have 200 drawings and all of them is in different folders.
That program is not so good. I can only add more then one drawing at the same time if they are in the same folder.

For that reason it will take long time to fix them all.
Is it not possible to change the symbol as easy as I change the titleblock?
Thank you.
Johan Sweden
0 Likes
Message 6 of 16

bradeneuropeArthur
Mentor
Mentor
Yes.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 16

bradeneuropeArthur
Mentor
Mentor

Could you please upload the following:

With this code it will work:

 

Public Sub updateSymbols()

Dim a As Application
Set a = ThisApplication

Dim b As DrawingDocument
Set b = a.ActiveDocument

Dim temp As DrawingDocument
Set temp = a.Documents.Open("C:\Vault\Projects\Temp.dwg", False)' This needs to be your template drawing.

Dim sks As SketchedSymbolDefinition
Set sks = temp.SketchedSymbolDefinitions.Item(1)

'MsgBox (sks.Name)

For Each sks In temp.SketchedSymbolDefinitions
Call sks.CopyTo(b, True)
Next

End Sub

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 8 of 16

autodeskpelinder
Enthusiast
Enthusiast
Thank you for the quick reply. I will try it tomorrow.
But I don't think I can use "set".
When I have tried it before Inventor show an error that tells me that set-command is no longer in use.
Kind regards Johan
Johan Sweden
0 Likes
Message 9 of 16

bradeneuropeArthur
Mentor
Mentor
Accepted solution

For i-ogic

 

Public Sub main()
 Dim a As Application
  a = ThisApplication 
Dim b As DrawingDocument 
 b = a.ActiveDocument 
Dim temp As DrawingDocument 
temp = a.Documents.Open("C:\Vault\Projects\Temp.dwg", False)' This needs to be your template drawing. 
Dim sks As SketchedSymbolDefinition
sks = temp.SketchedSymbolDefinitions.Item(1) 
'MsgBox (sks.Name) 
For Each sks In temp.SketchedSymbolDefinitions
 Call sks.CopyTo(b, True) 
Next
 End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 16

autodeskpelinder
Enthusiast
Enthusiast

Hi!

Thank you very much!

I could not put my rule in your rule, then I get an error:

Rule Compile Errors in Byta symbol, in 14363.idw

Error on Line 3 : Application är tvetydigt. Importerat från namnområdena eller typerna Inventor, System.Windows.Forms.

 

But if I run my rule from yours it works 🙂

But I can still only change one symbol at the time:

 

SyntaxEditor Code Snippet

Public Sub Main()
 Dim a As Application
  a = ThisApplication 
Dim b As DrawingDocument 
 b = a.ActiveDocument 
Dim temp As DrawingDocument 
temp = a.Documents.Open("R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw", False)' This needs to be your template drawing. 
Dim sks As SketchedSymbolDefinition
sks = temp.SketchedSymbolDefinitions.Item(1) 
'MsgBox (sks.Name) 
For Each sks In temp.SketchedSymbolDefinitions
 Call sks.CopyTo(b, True) 
Next

iLogicVb.RunExternalRule("Byt rithuvud")
End Sub

'============================================ My rule =======================================
SyntaxEditor Code Snippet
Try
ThisDrawing.ResourceFileName = "R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw"

ThisDrawing.KeepExtraResources = True

Dim oDrawDoc = ThisApplication.ActiveDocument
	 
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument
'oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols

Dim oCurrentNumber  As Sheet
oCurrentNumber = oDoc.ActiveSheet

' Iterate through the sheets, and delete the title blocks and symbols
For Each oSheet In oDoc.Sheets
    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
    Else 
    End If
    Next
	'============ Lägger in rätt symbol på rätt ställe
	Try
'Dim oDrawDoc As DrawingDocument = ThisDrawing.Document ' Set a reference to the drawing document. This assumes a drawing document is active.
'Dim oDrawDoc = 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
	Catch
		MessageBox.Show("Symbolen gick inte att byta, regeln kör vidare.", "Fel")
End Try

        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
Catch
	MessageBox.Show("Regeln gick inte att köra. Ritningen sparas som dwg.", "Fel")
End Try

'============== Sparar ritningen som dwg. Med samma namn och på samma plats.
Try
	If iProperties.Value("Project", "Revision Number") = "" Or
	iProperties.Value("Project", "Revision Number") = " " Or
	iProperties.Value("Project", "Revision Number") = "-"
	r = 1
	End If
	
	If r <> 1 'Om det finns rev så är r INTE = 1.
	ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & " Rev " & iProperties.Value("Project", "Revision Number") & (".dwg") , True)
	Else
		ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & (".dwg") , True)
	End If
	
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
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True

ThisApplication.ActiveView.Fit



Johan Sweden
0 Likes
Message 11 of 16

bradeneuropeArthur
Mentor
Mentor

change to this:

 

Public Sub Main()
 Dim a As Application
  a = ThisApplication 
Dim b As DrawingDocument 
 b = a.ActiveDocument 
Dim temp As DrawingDocument 
temp = a.Documents.Open("R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw", False)' This needs to be your template drawing. 
Dim sks As SketchedSymbolDefinition
'sks = temp.SketchedSymbolDefinitions.Item(1) 
'MsgBox (sks.Name) 
For Each sks In temp.SketchedSymbolDefinitions
 Call sks.CopyTo(b, True) 
Next

iLogicVb.RunExternalRule("Byt rithuvud")
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 16

autodeskpelinder
Enthusiast
Enthusiast

I get the same error when I run our rules together.

It doesn't like:
"Dim a As Application".

 

I still get this error:

Rule Compile Errors in Byta symbol, in 14363.idw

Error on Line 3 : Application är tvetydigt. Importerat från namnområdena eller typerna Inventor, System.Windows.Forms.

 

Google translate:

The application is ambiguous. Imported from the namespaces or types Inventor, System.Windows.Forms.

 

Maybe it is because I also use "ThisApplication.ActiveDocument" later in the code. But I tried to change my oDrawDoc to b, but it is the same.

 

First your:

SyntaxEditor Code Snippet

Dim a As Application
  a = ThisApplication 
Dim b As DrawingDocument 
 b = a.ActiveDocument 

 

Then in mine:

SyntaxEditor Code Snippet

Dim oDrawDoc = ThisApplication.ActiveDocument

 

Johan Sweden
0 Likes
Message 13 of 16

bradeneuropeArthur
Mentor
Mentor
For me it works!

What version of inventor are you using?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 14 of 16

autodeskpelinder
Enthusiast
Enthusiast

2018.2.3

It is okay. I can run my rule from yours, so I don´t need to have it all in one rule.

 

But it would be nice to run it in one rule and replace more then one symbol at that rule too.

Thank you for your help.

 

Strange that you can run this:

SyntaxEditor Code Snippet

Public Sub main()
 Dim a As Application
  a = ThisApplication 
Dim b As DrawingDocument 
 b = a.ActiveDocument 
Dim temp As DrawingDocument 
temp = a.Documents.Open("R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw", False)' This needs to be your template drawing. 
Dim sks As SketchedSymbolDefinition
'sks = temp.SketchedSymbolDefinitions.Item(1) 
'MsgBox (sks.Name) 
For Each sks In temp.SketchedSymbolDefinitions
 Call sks.CopyTo(b, True) 
Next

Try
ThisDrawing.ResourceFileName = "R:\Projekt\180 - ETK AB\180602 - Bodens Värmeverk - P18\3D-projekt\Inventor\Templates\Standard.idw"

ThisDrawing.KeepExtraResources = True

Dim oDrawDoc = ThisApplication.ActiveDocument
	 
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument
'oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols

Dim oCurrentNumber  As Sheet
oCurrentNumber = oDoc.ActiveSheet

' Iterate through the sheets, and delete the title blocks and symbols
For Each oSheet In oDoc.Sheets
    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
    Else 
    End If
    Next
	'============ Lägger in rätt symbol på rätt ställe
	Try
'Dim oDrawDoc As DrawingDocument = ThisDrawing.Document ' Set a reference to the drawing document. This assumes a drawing document is active.
'Dim oDrawDoc = 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
	Catch
		MessageBox.Show("Symbolen gick inte att byta, regeln kör vidare.", "Fel")
End Try

        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
Catch
	MessageBox.Show("Regeln gick inte att köra. Ritningen sparas som dwg.", "Fel")
End Try

'============== Sparar ritningen som dwg. Med samma namn och på samma plats.
Try
	If iProperties.Value("Project", "Revision Number") = "" Or
	iProperties.Value("Project", "Revision Number") = " " Or
	iProperties.Value("Project", "Revision Number") = "-"
	r = 1
	End If
	
	If r <> 1 'Om det finns rev så är r INTE = 1.
	ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & " Rev " & iProperties.Value("Project", "Revision Number") & (".dwg") , True)
	Else
		ThisDoc.Document.SaveAs(ThisDoc.Path & "\" & ThisDoc.FileName(False) & (".dwg") , True)
	End If
	
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
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True

ThisApplication.ActiveView.Fit
' JOPE 2016-03-30  2018-02-21

End Sub


 

 

Johan Sweden
0 Likes
Message 15 of 16

bradeneuropeArthur
Mentor
Mentor

Try the following:

 

Error.png

 

and take a look where the error occurs

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 16 of 16

autodeskpelinder
Enthusiast
Enthusiast

It is still the same 😞

Please see the attached picture.

Johan Sweden
0 Likes