I have a flat pattern feature in a part and wish to turn it on/off based on conditions controlled from an assembly. Basically the code I have works perfectly well within the part but I wish to fire the rule from the above assembly but the rule fails (presumenbly because the code refers to the current open part). Does anyone know how to adapt this code so it can be fired from an assembly?
Cheers
Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oSMDef As SheetMetalComponentDefinition oSMDef = oDoc.ComponentDefinition Dim oFlatFeatures As FlatPatternFeatures oFlatFeatures = oSMDef.FlatPattern.Features 'Define all the features you want to work with Dim oExtrudeFeature As ExtrudeFeature = oFlatFeatures.Item("10mm ADDITION") Try If SPIGOT_REVOLUTION <> 180 Then 'Create an Object collection To add the features For suppression Dim oCADlineSuppress As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 'Add each feature that you want to suppress to the collection oCADlineSuppress.Add(oExtrudeFeature) 'Suppress everything in this collection oSMDef.FlatPattern.SuppressFeatures(oCADlineSuppress) Else 'Create an object collection to add the features for unsuppression Dim oCADlineUnSuppress As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 'Add each feature that you want to unsuppress to the collection oCADlineUnSuppress.Add(oExtrudeFeature) 'Unsuppress everything in this collection oSMDef.FlatPattern.UnsuppressFeatures(oCADlineUnSuppress) End If Catch End Try
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
When you run this rule within the assembly it should get
the runtime error at the second line because the active document is not a part but an assembly.
Try to replace the first two lines with the following line
Dim oDoc As PartDocument = ThisDoc.Document
ThisDoc returns the reference to the document where the current rule is stored.