iLogic / VBA

iLogic / VBA

Anonymous
Not applicable
2,200 Views
10 Replies
Message 1 of 11

iLogic / VBA

Anonymous
Not applicable

 Hi,

I have a model with numerous sketch planes (more than 100), and in each sketch i need  "project cut edges" feture.

I have written a code that automatically creates workplanes and some sketches, to proceed further i need to have 'project cut edges' feature in all my sketches that i have created. The code i used is pasted below. Could someone help me proceed further?

 

SyntaxEditor Code Snippet

Sub Main()
    For i=1 To 10
        oDef = ThisDoc.Document.ComponentDefinition
        Dim oWPlane As WorkPlane
        oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), i, cm)
        oWPlane.Name = "My_New_Work_Plane"&i
        Dim oSketch As PlanarSketch
        oSketch = oDef.Sketches.Add(oWPlane)
           oSketch.Name = "My_Sketch"&i
        Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry
        Dim oWorkPoint As WorkPoint
        oWorkPoint = oDef.WorkPoints.AddFixed(oTG.CreatePoint(0, 0, i))
    Next
End Sub

 

 

0 Likes
Accepted solutions (1)
2,201 Views
10 Replies
Replies (10)
Message 2 of 11

rikard.nilsson
Collaborator
Collaborator

Hi,

 

Does it have to be Project Cut Edges?

 

Here is the code if Project Geometry is enough..

 

SyntaxEditor Code Snippet

Sub Main()
 oDef = ThisDoc.Document.ComponentDefinition
        Dim ExtrudeFeature As ExtrudeFeature
        ExtrudeFeature = oDef.Features.ExtrudeFeatures.Item("Extrusion2")
        
        Dim topFace As Face = ExtrudeFeature.EndFaces.Item(1)
        
        Dim oEdges as Edges = topFace.Edges

    For i=1 To 10
       
        Dim oWPlane As WorkPlane
        oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), i, cm)
        oWPlane.Name = "My_New_Work_Plane"&i
        Dim oSketch As PlanarSketch
        oSketch = oDef.Sketches.Add(oWPlane)
           oSketch.Name = "My_Sketch"&i
        Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry
        Dim oWorkPoint As WorkPoint
        oWorkPoint = oDef.WorkPoints.AddFixed(oTG.CreatePoint(0, 0, i))
        
        Dim oEdge As Edge
        For Each oEdge In oEdges
            oSketch.AddByProjectingEntity(oEdge)
        Next
    Next
End Sub

 

I also added my testpart for you to use..

 

Regards

Rikard 

0 Likes
Message 3 of 11

Anonymous
Not applicable

Hi Rickard,

 

Thanks for the code..It works..But i need only "Project Cut Edges". I could not find the syntax for it...

Cound one more option be to Call the sketch function? But still i would need the syntax for calling.

I found this in the VBA Editor..But figuring out how to use it!

 

Capture.JPG

0 Likes
Message 4 of 11

rikard.nilsson
Collaborator
Collaborator
Hi,

I think this will be easier to solve if you give some more information.
I think it would be nice if you add you part, pictures and more specific information how everything should work.

Is it possible to have a solution that uses some workflow with user interaction? If so.. How?

/Rikard
0 Likes
Message 5 of 11

Anonymous
Not applicable

Hi,

 

Ok..I have attached an ipt file along with this...the following is my design process steps, which can be seen from the Part file model tree in Inventor.

1. Create a solid body. In this case, a loft is created of height 200 mm.

2. Then create three workplanes, each at 50,100,150 mm 

3. Create three sketch planes at these workplanes created in previous step. 

4. In each sketchplane, I have used "Project Cut Edges" to get the solid body contour at each plane.

5. Export these skecthes in .dxf format.

Basically, I need to slice the solid body at different heights from the ground plane( the height is a variable here ) and export the contour sketch at different heights in DXF format.

It is easier to do manually when there is only 3 sections as in this case. But, in some cases it goes upto 150 sections for which i am trying to use iLogic/VBA.

The code that I posted creates 10 workplanes and 10 sketches. I thought this could be a way to achieve what i need. With my code I could right now create as many number of sketches as possible at required heights.

Is there any other better solution to get contour at different slicing cross-sections?

 

Capture.JPG

0 Likes
Message 6 of 11

rikard.nilsson
Collaborator
Collaborator
Accepted solution

Hi,

 

Here is the solution with making Projected Cuts..

It was much easier than expected..  🙂

 

SyntaxEditor Code Snippet

Sub Main()
 oDef = ThisDoc.Document.ComponentDefinition
    For i=1 To 8
       
        Dim oWPlane As WorkPlane
        oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), i, cm)
        oWPlane.Name = "My_New_Work_Plane"&i
        Dim oSketch As PlanarSketch
        oSketch = oDef.Sketches.Add(oWPlane)
           oSketch.Name = "My_Sketch"&i
        Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry
        Dim oWorkPoint As WorkPoint
        oWorkPoint = oDef.WorkPoints.AddFixed(oTG.CreatePoint(0, 0, i))
        
        oSketch.ProjectedCuts.Add()

    Next
End Sub

 

 

/Rikard 

Message 7 of 11

Anonymous
Not applicable

Thanks a lot !! That works perfectly.

0 Likes
Message 8 of 11

Anonymous
Not applicable

When I try this in Inventor Professional 2018 I get a compile error at oSketch = oDef.Sketches.Add(oWPlane), saying "Invalid use of property". Any ideas?

0 Likes
Message 9 of 11

Anonymous
Not applicable

Ignore my last post. The code works well. I was trying in VBA instead of iLogic. Ooops. 

0 Likes
Message 10 of 11

sam
Advocate
Advocate

@rikard.nilsson Any idea how to fix that error in VBA?

0 Likes
Message 11 of 11

rikard.nilsson
Collaborator
Collaborator

Hi!

 

have you changed the code so it’s written to work in VBA?

iLogic is VB.net and VBA is more like VB6. 

in almost every example in API help is VBA. If you look there you can for example se the “Set” is used when setting a variable. 

/Rikard