iLogic ----> Stitch Composite Surface Body

iLogic ----> Stitch Composite Surface Body

joris.engelbertink
Enthusiast Enthusiast
1,774 Views
12 Replies
Message 1 of 13

iLogic ----> Stitch Composite Surface Body

joris.engelbertink
Enthusiast
Enthusiast

Hi All,

 

I would like to use iLogic to "Stitch" a Composite Surface Body and make it a Solid.

 

I have some code that "Stitches" two individual surfaces, but it fails on one single Composite Surface Body.

 

I think a solution is very close, any help or suggestions is much appreciated!

 

Thanks. Grt, Joris

 

code:

Sub Main()
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument

    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition
    
    Dim oSurfaces As ObjectCollection
    oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection
    
    oSurfaces.Add (oCompDef.WorkSurfaces.Item(1))
    oSurfaces.Add (oCompDef.WorkSurfaces.Item(2))
    
    Dim oKnitFeature As KnitFeature
    oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)
End Sub

 

 

PS: When looking at the Object Model Tree there are two items that seem suitable for accessing the Composite Surface Body: WorkSurfaces and SurfaceBodies. A simple test shows there's 1 Worksurface and no SurfaceBody in the specific Composite part I want to convert. So accessing should work somehow with oCompDef.Worksurfaces.something-something? 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
1,775 Views
12 Replies
Replies (12)
Message 2 of 13

joris.engelbertink
Enthusiast
Enthusiast

the procedure within the Inventor environment is to first select the items, and then run the command Stitch.

 

would there be a similar way with the use of iLogic?

 

no reactions so far, no smart programming m/f in the house?

 

help is much appreciated 😉

 

Grt, Joris

0 Likes
Message 3 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

The code is correct and works. You need at least two surfaces to stitch together. Both need to share minimum one edge. If the stiched surfaces encloses a volume, Inventor will automatically create it. If your Composite Surface Body is not recognized as volume, there is a open area you need to find and correct it.

Or, if possible, post your part here and we can investigate it.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 13

joris.engelbertink
Enthusiast
Enthusiast

Hi, thanks for your reply. I added the file. 

 

At start there's 1 WorkSurface and no Solids. After running the Stitch command there's 1 WorkSurface and a Solid.

 

So it should also be possible to make this work with some code?

 

Grt, Joris   

 

 

 

 

0 Likes
Message 5 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

Take your code from above and remove the second oSurfaces.Add line. That's all.

Ever thought at least two worksurfaces are necessary. Something new every day. 😁


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 13

joris.engelbertink
Enthusiast
Enthusiast

Hi, 

 

That results in a "Parameter Incorrect" 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.KnitFeatures.Add(ObjectCollection Surfaces, Double MaximumTolerance, Boolean MaintainAsSurface)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

Grt, Joris

 

 

0 Likes
Message 7 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

If I take your part file and let the code run it creates a solid. The error message seems you call this rule from another and something is wrong with that?

Sub Main()
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument

    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition
    
    Dim oSurfaces As ObjectCollection
    oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection
    
    oSurfaces.Add (oCompDef.WorkSurfaces.Item(1))
    
    Dim oKnitFeature As KnitFeature
    oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 8 of 13

joris.engelbertink
Enthusiast
Enthusiast

I pasted the code and get the error. You got this working? also Inventor 2018?

 

what could it be? 

0 Likes
Message 9 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

Yes, it worked. Opened your file, pasted the code to a new rule and run. But I'm using Inventor 2021. I found an old thread wih a similar problem, but no solution. Are all updates for 2018 installed?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 10 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

I've additionally tested with Inventor 2020. There's the same error as in 2018. It seems there is an improvement in the API in 2021. Since then you need minimum 2 worksurfaces.

Do you import this part? Is it possible to import as solid?

As a workaround try the following.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oNPBFeature As NonParametricBaseFeature
oNPBFeature = oCompDef.Features.NonParametricBaseFeatures.Item(1)
    
Dim oSurfaceBody As SurfaceBody
oSurfaceBody = oNPBFeature.SurfaceBodies.Item(1)

Call oCompDef.Features.NonParametricBaseFeatures.Add(oSurfaceBody)

Call oCompDef.Features.NonParametricBaseFeatures.Item(1).Delete

Dim oSurfaces As ObjectCollection
oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection

Dim oWorkSurface As WorkSurface
For Each oWorkSurface In oCompDef.WorkSurfaces
    Call oSurfaces.Add(oWorkSurface)
Next

Dim oKnitFeature As KnitFeature
oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 11 of 13

gerrardhickson
Collaborator
Collaborator

I've  encountered the same problem. I suspect the problem is with the API.

The code posted by @Ralf_Krieg doesn't seem to help. Creating a new NPB and deleting the original one doesn't change anything - still the same number of faces.

I suspect the only way around it is to identify a planar face on your model, extract the edge loops (for later), delete that planar face, then use the edge loops to create a patch feature (thereby creating a second worksurface), then you can stitch the two worksurfaces together.

 

I'll try tomorrow.

0 Likes
Message 12 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

With the file the thread starter posted, my code creates 108 separate worksurfaces instead of 1 composite. This is definitly not the same as the original. With the worksurfaces it's possible to stitch the given objects to a solid.

 

If you want to go an alternative way with a boundary patch, here's my solution.  Assuming there's at least one planar face. If not, this will not work.

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oNPBFeature As NonParametricBaseFeature
oNPBFeature = oCompDef.Features.NonParametricBaseFeatures.Item(1)
    
Dim oSurfaceBody As SurfaceBody
oSurfaceBody = oNPBFeature.SurfaceBodies.Item(1)

Dim oFace As Face

For Each oFace In oSurfaceBody.Faces
	If oFace.SurfaceType=SurfaceTypeEnum.kPlaneSurface Then Exit For
Next

If oFace Is Nothing Then 
	Exit Sub
End If

Dim oBPDef As Inventor.BoundaryPatchDefinition = oCompDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition

For Each oEdgeLoop In oFace.EdgeLoops
	oBPDef.BoundaryPatchLoops.Add(oEdgeLoop)
Next

Dim oBP As BoundaryPatchFeature= oCompDef.Features.BoundaryPatchFeatures.Add(oBPDef)
Dim oSurfacesToStitch As ObjectCollection= ThisApplication.TransientObjects.CreateObjectCollection

Call oSurfacesToStitch.Add(oBP.SurfaceBodies.Item(1))
Call oSurfacesToStitch.Add(oCompDef.WorkSurfaces.Item(1).SurfaceBodies.Item(1))

Dim oKnitFeature As KnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfacesToStitch)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 13 of 13

gerrardhickson
Collaborator
Collaborator

Thanks @Ralf_Krieg for that. There must have been something wrong with the way I implemented your first set of code-  I was left with a copy of the first surface only. No other changes.

In any case, the second set of code works - thats' just what I planned. Many thanks.

0 Likes