- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I think you need to change this line:
Dim smDef As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinitionBecause with the new rule "ThisDoc.Document" is a drawing document. You should be accessing your "oPart" Object:
Dim smDef As SheetMetalComponentDefinition = oPart.ComponentDefinitionBut you will probably want to verify the "oPart" from the view is a sheet metal part or the above line will fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried that but didn't work as well.
But ty for your help!
João Silva
Mechanical Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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