Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JoãoASilva
2359 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