iLogic - Get model sketch

iLogic - Get model sketch

Anonymous
Not applicable
2,278 Views
10 Replies
Message 1 of 11

iLogic - Get model sketch

Anonymous
Not applicable

Greetings everyone,

 

I found a beautiful video from Curtis, but I can not find the code or command to Get Model Sketch

 

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/screencast/Main/Detail...

 

Can anyone help? 

 

Thanks,

Michal

0 Likes
Accepted solutions (1)
2,279 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

I modified another macro. It works perfect on part.

 

But the question is, how can i modifi this macro on flat pattern sketch?

 

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document

oView = oDrawingDoc.ActiveSheet.DrawingViews(1)


Dim oPart As PartDocument
oPart = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oPartDef As PartComponentDefinition
oPartDef = oPart.ComponentDefinition

Dim oSketch As PlanarSketch

For Each oSketch In oPartDef.Sketches

		Call oView.SetVisibility(oSketch, True)
	
	
Next
0 Likes
Message 3 of 11

bradeneuropeArthur
Mentor
Mentor
what do you mean with flatpattern sketch?

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 4 of 11

MechMachineMan
Advisor
Advisor
Accepted solution

Not necessarily the most robust way, but this should work for you:

 

Please also note that if you can't expose the sketch through the UI (i.e.; the view is flipped the wrong way), you won't be able to do it through the code - unless you modify the code to handle that situation. Easiest way would be to just flip the view and try the rule again.

 

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document

oView = oDrawingDoc.ActiveSheet.DrawingViews(1)

Dim oPart As PartDocument

Try

    oPart = oView.ReferencedDocumentDescriptor.ReferencedDocument
Catch
	MsgBox("Base View is not of a part!" & vbLf & vbLf & "Aborting Rule!")
	Exit Sub
End Try

Dim oGenericComponentDefinition As ComponentDefinition

Try
    Dim oSMCD As SheetMetalComponentDefinition
    oSMCD = oPart.ComponentDefinition
	oGenericComponentDefinition = oSMCD.FlatPattern
Catch
    Dim oPartDef As PartComponentDefinition
    oPartDef = oPart.ComponentDefinition
    oGenericComponentDefinition = oPartDef
End Try


Dim oSketch As PlanarSketch

For Each oSketch In oGenericComponentDefinition.Sketches
	Call oView.SetVisibility(oSketch, True)	
Next

 


--------------------------------------
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 11

Anonymous
Not applicable
Thank you very much, that's what I was looking for
0 Likes
Message 6 of 11

Vitalla
Contributor
Contributor

I have an assembly with parts below it that I need to get their  sketches. I tried to combine two bits of code I've found the one mentioned  and to recursively navigate the assembly to find the sketches.  It seems to run without errors, and through a message box I can verify I have the correct view & correct sketch I want to make visible I am unsure why it is not showing up. Any help would be appreciated, it seems in the video above by Curtis he was managing to make sketches show from an assembly.

 

Thanks!

 

Sub Main()
Dim oDrawingDoc As DrawingDocument
	oDrawingDoc = ThisDoc.Document
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oAssm As AssemblyDocument
Dim Occurrences As ComponentOccurrences
Dim oSheets As Sheets
	oSheets = oDrawingDoc.Sheets 
	
	
	For Each oSheet In oSheets
		oViews = oSheet.DrawingViews	
		For Each oView In oViews
			If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
                Dim RefDoc As AssemblyDocument
                	RefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
                'recurse all components in assembly referenced by view
                Call recurseOccurrences(RefDoc.ComponentDefinition.Occurrences,oView)
            End If
        Next
    Next
	

End Sub

Sub recurseOccurrences(Occurrences As ComponentOccurrences,oView As DrawingView)'oView As DrawingView
	
	    Dim Occurrence As ComponentOccurrence
   			For Each Occurrence In Occurrences
        		If Occurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
           		 	'found assembly, find subparts
           			 Call recurseOccurrences(Occurrence.SubOccurrences,oView)
        		ElseIf Occurrence.DefinitionDocumentType = kPartDocumentObject And InStr(LCase(Occurrence.Name), "tf_sk") Then
            							
					If oView.ParentView Is Nothing Then
						Exit Sub
					End If
						Dim oGenericComponentDefinition As PartComponentDefinition
					    	oGenericComponentDefinition = Occurrence.definition
						Dim oSketch As Sketch

						For Each oSketch In oGenericComponentDefinition.Sketches 
							oView.SetVisibility(oSketch, True)
							MsgBox( oSketch.Name )
							
						Next
            	End If
    		Next

End Sub
0 Likes
Message 7 of 11

madstrolle
Enthusiast
Enthusiast

I have tried all the different codes in this post. 

When I use this code, which works fine, I get all sketches from the part.

I have 1 specific sketch that I want to get from the part.

The best solution would be, if i could run the rule and the choose which view i want to call the model sketches. And then get the correct sketch that i'm looking for. Maybe call the sketch by name.  

0 Likes
Message 8 of 11

madstrolle
Enthusiast
Enthusiast

The pictures shows what i mean.

First picture is whitout model sketches.

Second picture is after running the rule, but as you can see all sketches are shown. I only want the one with the red arrow.

0 Likes
Message 9 of 11

MechMachineMan
Advisor
Advisor
You should be able to use my previous code but modify to have a Pick
command with a View Filter applied to it.

>From there, you could either have a hard-coded sketch name format that you
use in all dwgs for which one you want exposed, or pop up a list box (or
even a loop of message boxes) to help you pick the proper sketch to show.

--------------------------------------
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 10 of 11

madstrolle
Enthusiast
Enthusiast

You are saying all the right things, but unfortunately i'm not a champ at this.

Could you maybe help me, it would be very much appreciated.

Thank you in advance.

0 Likes
Message 11 of 11

MechMachineMan
Advisor
Advisor
No one starts out a champ either! Fortunately, with some persistence,
getting working code after you have a general understanding of object
oriented programming isn't too difficult with the availability of close
solutions and API documentation.

I would suggest perusing the autodesk developer documentation (API
documentation) to get more info on the commands and then string things
together.

Would love to help more, but I don't have time to be googling and stringing
things together myself.

--------------------------------------
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