Go to all Sheets

Go to all Sheets

martinhoos
Advocate Advocate
1,277 Views
6 Replies
Message 1 of 7

Go to all Sheets

martinhoos
Advocate
Advocate

Hi All,

i have two rules, first one changes the title block and the boom style, second one changes a sketched symbol. The code runs only if i have one sheet.

Need help to run the code through  all Sheets.

 

First one:

 

ActiveSheet.TitleBlock = "ET-Liste Deutsch"

Dim openDoc As Document
openDoc = ThisDoc.Document
 
'Dim docFile As Document
 
If openDoc.DocumentType = 12292 Then
 
    'Look For the model referenced within the drawing. End the Rule If the drawing Is empty.
    Dim MDocFile As Document
    If ThisDoc.ModelDocument IsNot Nothing Then
         MDocFile = ThisDoc.ModelDocument
         Else
         MessageBox.Show("Diese Option ist in einer leeren Zeichnung unzulässig", "Export error")
         Return
    End If
    
    'assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
        
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet
    'Look for partlist within drawing. End rule, if it doesn't exist.
    'say there is a Partslist on the sheet.
    Dim oPartslist As PartsList
    oPartslist = oSheet.PartsLists(1)
 
    If oSheet.PartsLists(1) IsNot Nothing Then
 
        'set parts list to a specific style
        oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item("KV-Stueli_Deutsch")
 
     End If
        
        
    Else
    MessageBox.Show("Es muss eine IDW offen sein um den Code zu verwenden!", "File Type Mismatch!")
    
End If


iLogicVb.RunRule("Flagge")

 

 

Second one:

 

Dim oIDW As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oIDW.ActiveSheet
' First view
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
' If base view
If oView.ViewType <> kStandardDrawingViewType Then
' If ref file is sheet metal
Dim oRefFile As Document = oIDW.ReferencedDocuments.Item(1)
Dim oSymbol As SketchedSymbol


If ActiveSheet.TitleBlock = "ET-Liste Deutsch" Then
' Define which symbol
Dim oSymDef_DE As SketchedSymbolDefinition
Dim oSymDef_EN As SketchedSymbolDefinition
oSymDef_DE = oIDW.SketchedSymbolDefinitions.Item("FL_Deutsch")
oSymDef_EN = oIDW.SketchedSymbolDefinitions.Item("FL_Englisch")

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet1 As Sheet
Dim oSymbols As SketchedSymbols

'iterate through all of the sheets
For Each oSheet1 In oSheets
    'remove existing sketched symbols named View Label 
    For Each oSymbol  In oSheet1.SketchedSymbols
    If oSymbol.Definition.Name = "FL_Englisch" Then
    oSymbol.Delete
	Else 
    End If
	Next
    
Next

' Check if symbol has been used
			If oSymDef_DE.IsReferenced Then Exit Sub

' Set position
Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(38,8)

' Insert symbol
oSymbol = oSheet.SketchedSymbols.Add(oSymDef_DE, oPosition)

End If

If ActiveSheet.TitleBlock = "ET-Liste Englisch" Then
' Define which symbol
Dim oSymDef_DE As SketchedSymbolDefinition
Dim oSymDef_EN As SketchedSymbolDefinition
oSymDef_DE = oIDW.SketchedSymbolDefinitions.Item("FL_Deutsch")
oSymDef_EN = oIDW.SketchedSymbolDefinitions.Item("FL_Englisch")

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet1 As Sheet
Dim oSymbols As SketchedSymbols

'iterate through all of the sheets
For Each oSheet1 In oSheets
    'remove existing sketched symbols named View Label 
    For Each oSymbol  In oSheet1.SketchedSymbols
    If oSymbol.Definition.Name = "FL_Deutsch" Then
    oSymbol.Delete
	Else 
    End If
	Next
    
Next

' Check if symbol has been used
			If oSymDef_EN.IsReferenced Then Exit Sub

' Set position
Dim oPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(38,8)

' Insert symbol
oSymbol = oSheet.SketchedSymbols.Add(oSymDef_EN, oPosition)

End If

End If

 

Thanks for your help....

 

Regards Martin

0 Likes
Accepted solutions (1)
1,278 Views
6 Replies
Replies (6)
Message 2 of 7

dgreatice
Collaborator
Collaborator

Hi Martin,

 

I think you don't need to set object Variabel like:

oSheet = oDrawDoc.ActiveSheet --> it always set to active sheet only

 

you can remove it.

 

Example my code:

 

.....

 

Dim oSheet As Sheet
For Each oSheet In oDrawDoc.Sheets

'type you statement here

'oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item("KV-Stueli_Deutsch")

next

 

....

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 7

martinhoos
Advocate
Advocate

Hello dgreatice,

thank you for your reply, i fixed my first code, it runs perfect. But i did'nt get the second one to run. I create this by copy and paste from other codes...

May be you can have a look   😉

Regards

Martin

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor

Much like Mike and Jim do not refer to the same person, oSheet1 and oSheet do not refer to the same variable (especially when used in a for loop *hint* *hint*).

 

Review your code and ensure your variable usage is consistent with what you want to accomplish.


--------------------------------------
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
Message 5 of 7

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

Can you help me to explain the end of result that code?


i assume, with my example :

 

1. You want to check each sheet with Title Block named (ET-Liste Deutsch) or (ET-Liste Englisch), is there any sketch symbol named (FL_Deutsch). and that sketch symbol you will deleted? else sketch symbol named (FL_Englisch) you will keep it?

2. ...

3. ...

 

with my assumption, this my trial code:

 

Dim oDwg As DrawingDocument
oDwg = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oSymbols As SketchedSymbols
Dim oSymbol As SketchedSymbol
Dim oPosition As Point2d

For Each oSheet In oDwg.Sheets
For Each oSymbol In oSheet.SketchedSymbols
oSymbols = oSheet.SketchedSymbols
If oSheet.TitleBlock.Name = "ET-Liste Deutsch" Then
If oSymbol.Definition.Name = "FL_Englisch" Then
oSymbol.Delete
End If

ElseIf oSheet.TitleBlock.Name = "ET-Liste Englisch" Then
If oSymbol.Definition.Name = "FL_Deutsch" Then
oSymbol.Delete
End If

End If
Next
Next

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 6 of 7

martinhoos
Advocate
Advocate

Hi Justin,

thank you for your replay, this gaves me an idea.

Regards

Martin

0 Likes
Message 7 of 7

martinhoos
Advocate
Advocate

Hi dgreatice,

thank you for your replay, your example gaves me an idea.

Regards Martin

0 Likes