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: 

[iLogic] Acessing Model Component Definition From Drawing

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
JoãoASilva
1987 Views, 6 Replies

[iLogic] Acessing Model Component Definition From Drawing

Hello All!

 

I'm trying to acess the Sheet Metal Component Definition of the model displayed on a drawing, but every way I try returns an error.

 

What I need:

I need a rule to check if the sheetmetal has any type of bends.

If it has, then  iProperties.Value("Summary", "Comments") = "Laser Cut + Bending"

If it doesn't  iProperties.Value("Summary", "Comments") = "Laser Cut"

 

What I have:

I have a rule inside a sheetmetal template that runs with a "before saving" trigger.

Dim smDef As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim pf As PartFeature

'set our custom properties to "Laser Cut" to start with..
iProperties.Value("Summary", "Comments") = "Laser Cut"

'loop through each part feature
For Each pf In smDef.Features
	If pf.Suppressed = False Then
If TypeOf pf Is FlangeFeature Then iProperties.Value("Summary", "Comments") = "Laser Cut + Bending" End If If TypeOf pf Is ContourFlangeFeature Then iProperties.Value("Summary", "Comments") = "Laser Cut + Bending" End If If TypeOf pf Is HemFeature Then iProperties.Value("Summary", "Comments") = "Laser Cut + Bending" End If If TypeOf pf Is FoldFeature Then iProperties.Value("Summary", "Comments") = "Laser Cut + Bending" End If
End If Next

 

What I want:

I want to check for bends on older sheetmetal parts were this rule wasn't yet implemented.

For this, I was considering acessing the part features thru the drawing.

All my drawings have multisheets.

 

Also, a few colleagues create sheetmetal parts by converting normal parts (I know this causes the SubType to be different from an originally created sheetmetal); sometimes they don't even convert, so they stay as "part".

For this reason, I want to filter when the rule runs using our coding scheme, wich I know how to do.

 

What I know:

I know how to go thru each and every sheet and fire rules based on the "in view model" subtype or part number.

 

My current code:

'['get full name of the model in the first view
Dim aDoc As DrawingDocument 
aDoc = ThisApplication.ActiveDocument

Dim aSheet As Sheet
Dim aViews As DrawingViews
Dim aView As DrawingView

aSheet = ActiveSheet.Sheet

aViews = aSheet.DrawingViews

If aViews.Count > 0 Then
	aView = aViews.Item(1)
	aModelFullName = aView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
End If']
	
'['Part variables
Dim oPart As PartDocument
Dim oPartPath As String
Dim FulloPartName As String
	
' Set a reference to the target part
FulloPartName = ThisDoc.Path
FulloPartName = FulloPartName & "\" & aModelFullName
oPart = ThisApplication.Documents.ItemByName(FulloPartName)
']
	
ThisApplication.Documents.Open(FulloPartName)
	
'['Check Bend
Dim smDef As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim pf As PartFeature

'set our custom properties to "Laser Cut" to start with..
iProperties.Value("Summary", "Comments") = "Laser Cut"

'loop through each part feature
For Each pf In smDef.Features
	If pf.Suppressed = False Then
		
		If TypeOf pf Is FlangeFeature Then
		iProperties.Value("Summary", "Comments") = "Laser Cut + Bending"
		End If
		
		If TypeOf pf Is ContourFlangeFeature Then
		iProperties.Value("Summary", "Comments") = "Laser Cut + Bending"
		End If
		
		If TypeOf pf Is HemFeature Then
		iProperties.Value("Summary", "Comments") = "Laser Cut + Bending"
		End If
		
		If TypeOf pf Is FoldFeature Then
		iProperties.Value("Summary", "Comments") = "Laser Cut + Bending"
		End If
		
	End If
Next']
	
oPart.Close

 The problem occurs on the " '['Check Bend " part.

 

What I have tried:

I replaced the "Check Bend" with a message box and everything else works.

I tried to run the "Check Bend" as an external rule, but to no avail.

 

Maybe I'm missing a simple detail or it just can't be done this way.

Any tips?

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

6 REPLIES 6
Message 2 of 7
J-Camper
in reply to: JoãoASilva

I think you need to change this line:

Dim smDef As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinition

Because with the new rule "ThisDoc.Document" is a drawing document.  You should be accessing your "oPart" Object:

Dim smDef As SheetMetalComponentDefinition = oPart.ComponentDefinition

But you will probably want to verify the "oPart" from the view is a sheet metal part or the above line will fail.

 

Message 3 of 7
WCrihfield
in reply to: JoãoASilva

Maybe try it this way:

 

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oPDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oSMFeats As SheetMetalFeatures
For Each oSheet As Inventor.Sheet In oDDoc.Sheets
	If oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oPDoc = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument
		If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			oSMDef = oPDoc.ComponentDefinition
			oSMFeats = oSMDef.Features
			If oSMFeats.FlangeFeatures.Count > 0 Or _
				oSMFeats.ContourFlangeFeatures.Count > 0 Or _
				oSMFeats.HemFeatures.Count > 0 Or _
				oSMFeats.FoldFeatures.Count > 0 Then
				oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value = "Laser Cut + Bending"
			End If
		Else 'it's a regular part (not sheet metal)
			oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value = "Laser Cut"
		End If
	'Else ' the model in the drawing view is not a part document, so do nothing, then next.
	End If
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7
JoãoASilva
in reply to: J-Camper

I tried that but didn't work as well.

But ty for your help!

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 5 of 7
JoãoASilva
in reply to: WCrihfield

I added a case to your working code and now it covers all my cases!

Before accepting as a solution, is there a simple way to make this code only applicable to one sheet?

That way I could just insert it in my fully functional "big macro", and run when the coding applies.

 

Ty!

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 6 of 7
WCrihfield
in reply to: JoãoASilva

OK. Try this then.

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oPDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oSMFeats As SheetMetalFeatures
If oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oPDoc = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument
	If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
		oSMDef = oPDoc.ComponentDefinition
		oSMFeats = oSMDef.Features
		If oSMFeats.FlangeFeatures.Count > 0 Or _
			oSMFeats.ContourFlangeFeatures.Count > 0 Or _
			oSMFeats.HemFeatures.Count > 0 Or _
			oSMFeats.FoldFeatures.Count > 0 Then
			oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value = "Laser Cut + Bending"
		End If
	Else 'it's a regular part (not sheet metal)
		oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value = "Laser Cut"
	End If
'Else ' the model in the drawing view is not a part document, so do nothing, then next.
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7
JoãoASilva
in reply to: WCrihfield

Your first answer was more than what I wanted, but was correct.

 

The second one is exactly what I needed.

 

Thank you!

João Silva

Mechanical Engineer

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report