how to guarantee to process a part document in its good model state under its top assembly with multiple model state

how to guarantee to process a part document in its good model state under its top assembly with multiple model state

junGQMXK
Enthusiast Enthusiast
219 Views
2 Replies
Message 1 of 3

how to guarantee to process a part document in its good model state under its top assembly with multiple model state

junGQMXK
Enthusiast
Enthusiast

hi, everyone,

 

I have an assembly. it has 8 model states. under this assembly, I have a sheet metal part which also has 8 model states to correspond to the 8 ones in the top assembly. I loop through the top assembly's model states and hence automatically put the sheet metal in its good model state.

then I try to calculate the sheet metal areas for the part in its different model states.

 

I simplified my program to the following simple program .I found that it seemed that I should do something extra to guarantee that I could capture my sheet metal part in its good model state just in order to calculate its areas in different model states.

 

my current running result showed that the function "SheetMetalPartExtendAreaCalculation" did not catch the good model state of the sheet metal, in fact it always used the first model state to calculate the area. So all the areas obtained were just the same values.

 

anyone knows what else I should do to guarantee that the function "SheetMetalPartExtendAreaCalculation" can handle a sheet metal part in its good model state?

 

thanks in advance.

 

 

Sub main()
For each oCurrentModelState As ModelState in oAllModelStatesInAssembly
 
oCurrentModelState.Activate
.
.
.
 
    dim oCurrentSheetMetalPartDocument as PartDocument = ..... ' here we found the sheet metal part document
.
.
.
 
        dim oCurrentSheetMetalPartArea= SheetMetalPartExtendAreaCalculation(oCurrentSheetMetalPartDocument)
 
 
next 
 
.
.
.
End sub
 
 
Function SheetMetalPartExtendAreaCalculation(oDoc1 As PartDocument) As Double
oDoc1.Update2(True) ' Force a rebuild
Dim oDef As SheetMetalComponentDefinition = oDoc1.ComponentDefinition
' Check that a flat pattern exists on the part in question
If IsNothing(oDef.FlatPattern) Then
' Try ' Try unfolding part
' oDef.Unfold()
' Catch ' Failed to unfold part
MessageBox.Show("There is no flat pattern in " & oDoc1.DisplayName,"Program Prompt")
Exit Function 
'End Try
End If
 
' Get the extend length and width
Dim SheetMetalLength As Double = oDef.FlatPattern.Length
Dim SheetMetalWidth As Double = oDef.FlatPattern.Width
logger.info(Str(SheetMetalLength)+Str(SheetMetalWidth))
Return Math.Round(SheetMetalLength * SheetMetalWidth* 0.155,3)'area unit is in^2
End Function

 

the following is the running result: it seems the part numbers were caught correctly, but the sheet area is only for the first model state of the sheet metal part, in fact the area for the second model state is another value.

 

I tried for so long a time and could not figure out the problem.

junGQMXK_0-1739289001362.png

 

0 Likes
Accepted solutions (1)
220 Views
2 Replies
Replies (2)
Message 2 of 3

MjDeck
Autodesk
Autodesk
Accepted solution

Hi @junGQMXK - it looks like there is a problem getting the correct sizes from a model state part in an assembly. The document that occurs in an assembly is a member document. It works if you get the factory document instead. See the attached rule.
I'll check to see if we have an issue logged for this. Maybe it has been fixed in a later release. If not, I'll create an issue.


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 3

junGQMXK
Enthusiast
Enthusiast

hi, Mike,

 

thank you very much!!! I tested your rule and it worked perfectly.

 

yes you are right, using the factory document is very important.

 

I have read your posts on the forum in the past 10 years, and each time I learned something. This was why I called your help this time when I met the above issue.

 

great thanks again!

 

 

 

0 Likes