iLogic - Lofting 2 Profiles (2D Sketches) with 1 Centerline (3D Sketch)

iLogic - Lofting 2 Profiles (2D Sketches) with 1 Centerline (3D Sketch)

jason_snyder
Enthusiast Enthusiast
1,980 Views
14 Replies
Message 1 of 15

iLogic - Lofting 2 Profiles (2D Sketches) with 1 Centerline (3D Sketch)

jason_snyder
Enthusiast
Enthusiast

Hi All,

I'm looking for code to simply loft 2 profiles along a centreline. I have multiple to do and looking to speed the process.

 

I assumed I need to define my profiles, centreline then define a loft. Hence, the code below:

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
   
    Dim oP1 As Profile, oP2 As Profile
    oP1 = oDoc.ComponentDefinition.Sketches("Section1").Profiles.AddForSolid
    oP2 = oDoc.ComponentDefinition.Sketches("Section2").Profiles.AddForSolid
    

            Dim oP3 As LoftDefinition.Centerline

             oP3 = oDoc.ComponentDefinition.Sketches("Path1").
    
    Dim oCol As ObjectCollection
    oCol = ThisApplication.TransientObjects.CreateObjectCollection
    oCol.Add oP1
    oCol.Add oP2

 

       Dim oLoftDef As LoftDefinition
       oLoftDef = oDoc.ComponentDefinition.Features.LoftFeatures.CreateLoftDefinition(oCol, kJoinOperation)
   
       Dim oLoftF As LoftFeature
       oLoftF = oDoc.ComponentDefinition.Features.LoftFeatures.Add(oLoftDef)

 

 

However, this doesn't work and errors out. How do it get the centreline to be added in?

 

0 Likes
Accepted solutions (1)
1,981 Views
14 Replies
Replies (14)
Message 2 of 15

Jon.Balgley
Alumni
Alumni

I am also having a problem specifying the centerline.  I am still investigating that.  The following will create a loft-feature without a centerline.

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim pcd = oDoc.ComponentDefinition
   
Dim oP1 As Profile, oP2 As Profile
oP1 = pcd.Sketches("Section1").Profiles.AddForSolid
oP2 = pcd.Sketches("Section2").Profiles.AddForSolid

Dim oCol As ObjectCollection
oCol = ThisApplication.TransientObjects.CreateObjectCollection
oCol.Add(oP1)
oCol.Add(oP2)

Dim oLoftDef As LoftDefinition
oLoftDef = pcd.Features.LoftFeatures.CreateLoftDefinition(oCol, kJoinOperation)

Dim oLoftF As LoftFeature
oLoftF = pcd.Features.LoftFeatures.Add(oLoftDef)
    
    
    

Jon Balgley
0 Likes
Message 3 of 15

jason_snyder
Enthusiast
Enthusiast

Hi Jon,

 

Thanks, I have been doing some further reading and I think maybe need to use a BoundaryCondition.

However, I'm struggling on how the syntax should read.

 

 

0 Likes
Message 4 of 15

Jon.Balgley
Alumni
Alumni

Can you construct the loft you want with the UI?  What options are you specifying?

 

The API documentation on the boundary conditions is pretty sparse!


Jon Balgley
0 Likes
Message 5 of 15

jason_snyder
Enthusiast
Enthusiast

No, yeah I thought a boundarypath perhaps? A EdgeCollection of the 3D sketch?

 

I found code for when the path is a 2D sketch which was simple. Defined as sketch. ("Path").proiles.addforsurface then defined as a centerline. Worked. But doesn't work with 3D Sketches.

 

 

 

 

 

0 Likes
Message 6 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @jason_snyder,

 

 

Try the following VBA code to create loft feature. The loft is created for 2 profiles (2D sketch) with 1 Centerline (3D sketch).

 

This code is tested with attached sample part file in Inventor 2018.

 

Sub CenterLineLoftCreation()
Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oComp As PartComponentDefinition Set oComp = oDoc.ComponentDefinition Dim oSections As ObjectCollection Set oSections = ThisApplication.TransientObjects.CreateObjectCollection oSections.Add oComp.Sketches(1).Profiles.AddForSolid oSections.Add oComp.Sketches(2).Profiles.AddForSolid Dim oDef As LoftDefinition Set oDef = oComp.Features.LoftFeatures.CreateLoftDefinition(oSections, kJoinOperation) oDef.Centerline = oComp.Sketches3D.Item(1).Profiles3D.AddOpen Dim oLoft As LoftFeature Set oLoft = oComp.Features.LoftFeatures.Add(oDef)
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 7 of 15

jason_snyder
Enthusiast
Enthusiast

Hi Chandra,

 

Thanks for this, works well.

 

However, not so well inside a "Simplified Part", where my sections and control line are derived from a assembly. 

 

I guess I'd need to change the code to look inside the derived assembly and not the "Simplified Part", Any thoughts for what that code is?

 

 

Cheers

0 Likes
Message 8 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @jason_snyder,

 

Can you please provide part which is using derived assembly?

 

Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 15

jason_snyder
Enthusiast
Enthusiast

Hi Chandra,

 

Please find attached zip file.

 

Very basic geometry. However, the concept is key.

 

Lofted_Part_1 is where I want to select my sections and control/centreline and loft.

 

Skel_assy_1 contains my assembled sections and control/centreline placed in correct locations.

 

Let me know how you go.

Cheers,

Jason Snyder

 

 

 

 

 

0 Likes
Message 10 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @jason_snyder,

 

Downloaded the attachment and opened part called "LOFTED_PART_1.ipt"

 

For some reason, sketch3D which is derived from assembly is not having "Profile3D" as shown in below image.

 

Profile3D.png

 

So, unable to create loft feature using 2dsketch and 3d sketch. which are derived from assembly.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 15

jason_snyder
Enthusiast
Enthusiast

Hi Chandra,

 

Thanks, this makes me think I need to make reference to the derived sketches?

 

Dim oDerPart As PartDocument
    oDerPart = ThisApplication.ActiveDocument
   
    Dim oDerPartComp As DerivedPartComponent
   
    oDerPartComp = oDerPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents("SKEL_ASSY_1.iam").Sketches("Sketch1").Profiles.AddForSolid
    oDerPartComp = oDerPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents("SKEL_ASSY_1.iam").Sketches("Sketch2").Profiles.AddForSolid

 

 

0 Likes
Message 12 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @jason_snyder,

 

 

No changes required for VBA code. Again, Sketch3D of centerline looks complex for Inventor API and unable to create profile3D for it.

 

Sub CenterLineLoftCreation()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim oComp As PartComponentDefinition
    Set oComp = oDoc.ComponentDefinition

    Dim oSections As ObjectCollection
    Set oSections = ThisApplication.TransientObjects.CreateObjectCollection

    oSections.Add oComp.Sketches(1).Profiles.AddForSolid
    oSections.Add oComp.Sketches(2).Profiles.AddForSolid

    Dim oDef As LoftDefinition
    Set oDef = oComp.Features.LoftFeatures.CreateLoftDefinition(oSections, kJoinOperation)

    oDef.Centerline = oComp.Sketches3D.Item(1).Profiles3D.AddOpen

    Dim oLoft As LoftFeature
    Set oLoft = oComp.Features.LoftFeatures.Add(oDef)

End Sub

 I modified sketch3D something look like as follow.

 

Curve3D.JPG

 

The same code is working fine and able to create loft feature. Tested sample attached with this post.

 

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 13 of 15

jason_snyder
Enthusiast
Enthusiast

Hi Chandra,

Cool, no worries. My geometry maybe too complex for "Simplified Parts".

 

Good to know it does work on less complex 3D Sketches.

 

Thanks again,

Cheers,

Jason Snyder  

0 Likes
Message 14 of 15

Anonymous
Not applicable

Hello, 

I have multiple 3d lines and 2d sketches. Is it possible to update this code so it can generate all the lofts? 

0 Likes
Message 15 of 15

Anonymous
Not applicable

Actually I managed to do that. Still, I have another problem!

What I want to do is I create a geometry, then I export the step file of this geometry and then I import this step file and I use your macro to create the sweep. 

Unfortunately, if it works well in the original part, it does not in the imported step file. It might because all the sketches are imported as 3D sketches, I believe. Then what would be the right code ?

Thank you for your help!

0 Likes