Finding Center of a flat pattern

Finding Center of a flat pattern

brianA32ZM
Advocate Advocate
978 Views
15 Replies
Message 1 of 16

Finding Center of a flat pattern

brianA32ZM
Advocate
Advocate

Hello, I am attempting to locate the center of a flat pattern (the side A is defined) to place a text box. My initial thought was to locate the center of the flat pattern range box by subtracting the Min point from the max point. This method appeared to work, however in some parts the text box falls. Is there a better method to locatedthe center of the flat pattern? Thanks in advance.

Dim oFlatPattern As FlatPattern = oCompDef.FlatPattern
oFlatPattPRR = oFlatPattern.RangeBox
oFlatPattPRR_X = oFlatPattPRR.MaxPoint.X - oFlatPattPRR.MinPoint.X
oFlatPattPRR_Y = oFlatPattPRR.MaxPoint.Y - oFlatPattPRR.MinPoint.Y
Dim oPoint2d As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((oFlatPattPRR_X / 2) + oFlatPattPRR.MinPoint.X, (oFlatPattPRR_Y / 2) -oFlatPattPRR.MaxPoint.Y)

 

0 Likes
Accepted solutions (1)
979 Views
15 Replies
Replies (15)
Message 2 of 16

Cadkunde.nl
Collaborator
Collaborator

Hello,

 

I did a small test with min and maxpoints of the flatpattern

 

But i seem to get weird min and maxpoint results when the flatpattern is rotated compared to folded model.

 

You can change rotation by double clicking the flat pattern, then 

Edit flatpattern definition.

 

Trying to see what works, but thought of sharing this first

0 Likes
Message 3 of 16

Cadkunde.nl
Collaborator
Collaborator

I made some screengrabs from my test.

When The flatpattern is rotated 90 degrees, Xmin becomes -4.4408etc

Knipsel.PNG

Couldnt find a solution but maybe this helps you a bit. Good luck

0 Likes
Message 4 of 16

brianA32ZM
Advocate
Advocate

Thank you. I need to test it, but I believe the range box would shift depending on the rotation point when rotating the flat pattern.

I should have noted that the X axis results appear to work as expected. The Y axis is the direction that results in the text box falling off the part.  

0 Likes
Message 5 of 16

WCrihfield
Mentor
Mentor

Hi @brianA32ZM & @Cadkunde.nl.  Are you trying to find the center of the FlatPattern's body (a 3D point), or just the center of one of its main faces (a 2D point)?  To get a more accureate center of the body (3D point), you could use the SurfaceBody object of the FlatPattern (from FlatPattern.Body), then you could use its SurfaceBody.OrientedMinimumRangeBox property to get an OrientedBox object, which would be more accurate when the model may not be perfectly rectangular or not aligned with origin axes/planes.  To get the center of a face, you could try creating a temporary sketch on the face, projects its outer profile to the sketch, then get its Profile object, then use the RegionProperties of that Profile, which has a property called Centroid.  That should return the most accurate center of the face you could get.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 16

brianA32ZM
Advocate
Advocate

Thank you. The goal is to find the center of a 2d face; I will test your method soon. 

0 Likes
Message 7 of 16

WCrihfield
Mentor
Mentor

Another idea, which may be a step simpler, would be to use the WorkPoints.AddAtCentroid method.  Then, as input for that method, you could use the EdgeLoop from the FlatPattern.BaseFace.EdgeLoops collection that returns True for its EdgeLoop.IsOuterEdgeLoop property.  Then you could use the position of that WorkPoint for your needs, then maybe delete the WorkPoint, as long as your point is not dependent on it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 16

brianA32ZM
Advocate
Advocate

Thanks again. I can place a workpoint on the formed part, but I get an error trying to place it on the flat pattern. Can you point me in the right direction?

 

        Dim oTO As TransientObjects = ThisApplication.TransientObjects


 For Each oEdgeloop As EdgeLoop In ThisApplication.ActiveDocument.componentDefinition.Flatpattern.BaseFace.EdgeLoops
              If Not oEdgeloop.IsOuterEdgeLoop Then
                    Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection
                    For Each oEdge In oEdgeloop.Edges
                        oEdgeColl.Add(oEdge)
                    Next
		   'Dim oWorkpoint As WorkPoint = ThisApplication.ActiveDocument.componentDefinition.WorkPoints.AddAtCentroid(oEdgeColl)
                    Dim oWorkpoint As WorkPoint = ThisApplication.ActiveDocument.componentDefinition.Flatpattern.WorkPoints.AddAtCentroid(oEdgeColl)
                   
                End If
            Next

 

0 Likes
Message 9 of 16

WCrihfield
Mentor
Mentor

Hi @brianA32ZM.  It looks like you are trying to work with every other EdgeLoop except for the outside one.  That seems odd to me.  Maybe remove the keyword 'Not' from that 'check' line to get only the one that is the outer edge loop.  There should only be one outer EdgeLoop, but it is possible to have multiple inner edge loops.  And if you add all the edges of multiple EdgeLoops to the EdgeCollection, that is probably where the problem is coming from.  It may only be able to find the center of one EdgeLoop at a time...or one EdgeCollection, only if all the edges within are connected.  The online help page for that method, at the link in my earlier response, includes some of this explanation of functionality.

Edit:  Wait...I misread the code you posted.  You are only attempting to create one WorkPoint per EdgeLoop.  Maybe you just need to 'Clear' the EdgeCollection each time, even though you are creating it new each time...just as a clean-up precaution.

Edit 2:  You may also just need to break down those long lines of code a bit, so it will recognize each objects Type.  That is sometimes an issue when using really long lines of code like that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 16

brianA32ZM
Advocate
Advocate

Thank you again. Sorry for the confusion, my coding knowledge is limited. I pulled that code from another forum post and tried to adapt it. I made the changes and the result was an error placing the work point on the Flat and success placing on the formed again.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim Flatpattern As FlatPattern = oCompDef.Flatpattern
Dim BaseFace As Face = Flatpattern.BaseFace
Dim EdgeLoops As EdgeLoops = BaseFace.EdgeLoops
Dim oTO As TransientObjects = ThisApplication.TransientObjects
For Each oEdgeloop As EdgeLoop In EdgeLoops If oEdgeloop.IsOuterEdgeLoop Then ' Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection ' For Each oEdge In oEdgeloop.Edges ' oEdgeColl.Add(oEdge) ' Next 'Dim oWorkpoint As WorkPoint = ThisApplication.ActiveDocument.componentDefinition.WorkPoints.AddAtCentroid(oEdgeColl) 'Dim oWorkpoint As WorkPoint = Flatpattern.WorkPoints.AddAtCentroid(oEdgeColl) Dim oWorkpoint As WorkPoint = Flatpattern.WorkPoints.AddAtCentroid(oEdgeloop) 'Dim oWorkpoint As WorkPoint = oCompDef.WorkPoints.AddAtCentroid(oEdgeloop) '**This work on the Formed Model End If Next

 

0 Likes
Message 11 of 16

WCrihfield
Mentor
Mentor

I can't believe that I forgot to mention this earlier, but I think you have to put the FlatPattern into 'Edit Mode' before you can make edits to it.  The FlatPattern object has two methods...one called Edit, and the other called ExitEdit, that I think you will have to use in this case.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 16

brianA32ZM
Advocate
Advocate

 

 

Well it still does not like me. I really appreciate the help! The error is shown below as well.

 

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim Flatpattern As FlatPattern = oCompDef.Flatpattern
Dim BaseFace As Face = Flatpattern.BaseFace
Dim EdgeLoops As EdgeLoops = BaseFace.EdgeLoops

Dim oTO As TransientObjects = ThisApplication.TransientObjects

oCompDef.FlatPattern.Edit()

For Each oEdgeloop As EdgeLoop In EdgeLoops
	If oEdgeloop.IsOuterEdgeLoop Then
'		Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection
'		For Each oEdge In oEdgeloop.Edges
'			oEdgeColl.Add(oEdge)
'		Next
		'Dim oWorkpoint As WorkPoint = ThisApplication.ActiveDocument.componentDefinition.WorkPoints.AddAtCentroid(oEdgeColl)
		'Dim oWorkpoint As WorkPoint = Flatpattern.WorkPoints.AddAtCentroid(oEdgeColl)
		Dim oWorkpoint As WorkPoint = Flatpattern.WorkPoints.AddAtCentroid(oEdgeloop)
		'Dim oWorkpoint As WorkPoint = oCompDef.WorkPoints.AddAtCentroid(oEdgeloop) '**This work on the Formed Model

	End If
Next

 

Error:

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.WorkPoints.AddAtCentroid(Object Entities, Boolean Construction)
at ThisRule.Main() in rule: Rule0, in document 23-8942-50-S.ipt:line 21
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 13 of 16

WCrihfield
Mentor
Mentor

I just opened one of my fairly simple sheet metal 'testing' files, and write some code in it for this task, to test it on my end.  I am also getting errors.  I am not 100% sure, but this might be restricted for some reason.  I know that creating work features in an assembly by code is pretty restricted also, but haven't really explored creating them much within the FlatPattern before.  We may have to fall back to the sketch routine I mentioned before.  I'm out for the day, but I may have another look at this tomorrow.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 16

brianA32ZM
Advocate
Advocate
0 Likes
Message 15 of 16

WCrihfield
Mentor
Mentor
Accepted solution

Hi @brianA32ZM.  Turns out that it did not like working with the value of the FlatPattern.BaseFace property, because as soon as I switched that to using FlatPattern.BottomFace, all my code variations started working.  I got both the WorkPoints.AddAtCentroid method to work, and the sketch routine to work.  Since both code variations have some length to them, I will opt to attach both of them to this post as a text file, to keep it clean, and short.  Give these a try, and let me know if they work for you, and if you need any further help with your main task.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 16 of 16

brianA32ZM
Advocate
Advocate

WCrihfield I cannot thank you enough. This issue has been plaguing me for way too long. In the end I used the WorkPoint solution. On the limited models I tested only one produced an odd result. It was on a simple disk where the work point was reported as being on the edge (0 , 3.81) of the outer profile when in reality it was at 0 , 0.  The location was gathered from: oPoint2d_X = oFaceCenter.Point.X & oPoint2d_X = oFaceCenter.Point.X

As I get time I would also like to test the other solution.

Thanks again! 

0 Likes