Using Inventor API to project geometry across parts into a 3D sketch

Using Inventor API to project geometry across parts into a 3D sketch

Anonymous
Not applicable
1,721 Views
4 Replies
Message 1 of 5

Using Inventor API to project geometry across parts into a 3D sketch

Anonymous
Not applicable

I have an assembly with two parts, and want to project a (2D) sketch on part1 into a new 3D sketch on part2 using inventors API. Here is a portion of the code I'm trying to use, I've been able to create the 3D sketch on part2 but haven't successfully projected the sketch from part1 into the one in part2:

 

Dim oSketch As Sketch3D = Pt2Def.Sketches3D.Add()

Dim oSketchProxy As Sketch3DProxy
oOcc.CreateGeometryProxy(oSketch, oSketchProxy)

Dim oProjectionEntity As SketchEntity3D = oSketchProxy.AddByProjectingEntity(pt1Def.Sketches.newSketch.sketch1Entity)

 

for clarity, sketch1Entity is a Sketch Entity in the 2D sketch on part 1.

Any advice on how to fix this issue or a different approach would be greatly appreciated.

0 Likes
Accepted solutions (1)
1,722 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

How complex is this geometry within the 2D sketch in Part1?

Would it be possible to gather data about the geometry within it, then use that data to recreate the sketch geometry within the other part?

Would simply copying the 2D sketch object from Part1 to Part2 work for you, then you could project it into your Sketch3d environment the way you want it manually?

This is a complex problem. Can you supply Inventor files to test with, and maybe some screen shots of the result you're hoping for.  How would we know where within that Sketch3d space to put the 2D geometry?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

In order to project sketch entities between two occurences you'll have to make proxies for both sketches.

The proxies are the sketches in the assembly context, which is required in order for them to have positions relative to eachother. I made a small sample iLogic rule for you.

Dim oDef As AssemblyComponentDefinition = ThisAssembly.Document.ComponentDefinition
Dim oOcc1 As ComponentOccurrence = oDef.Occurrences.ItemByName("3D") 'I have named the occurrence for 3d sketch "3D"
Dim oOcc2 As ComponentOccurrence = oDef.Occurrences.ItemByName("2D") 'I have named the occurrence with 2d sketch "2D"
Dim pDef1 As PartComponentDefinition = oOcc1.Definition
Dim pDef2 As PartComponentDefinition = oOcc2.Definition
Dim oSketch3d = pDef1.Sketches3D.Add
Dim oSketch3dProx As Sketch3DProxy
oOcc1.CreateGeometryProxy(oSketch3d, oSketch3dProx)
Dim oSketch2dProxy As PlanarSketchProxy
oOcc2.CreateGeometryProxy(pDef2.Sketches("Sketch1"), oSketch2dProxy) 'Name of sketch in my case "Sketch1"
For Each oEnt As SketchEntity In oSketch2dProxy.SketchEntities
	On Error Resume Next
	oSketch3dProx.Include(oEnt)
Next

assemblytree.PNG

Message 4 of 5

Anonymous
Not applicable

Thanks for the reply, for some reason the line 

oOcc1.CreateGeometryProxy(oSketch3d, oSketch3dProx)

isnt working for me, it causes an error and halts the program. Im Writing this code in an addin using VBA, im assuming the code you provided is VB.Net, and if it is do you know how it would be properly written in VBA?

 

 

0 Likes
Message 5 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Here's the same code in VBA:

Sub ProjectTo3D()
Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition
Set oDef = oAsm.ComponentDefinition
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oDef.Occurrences.ItemByName("3D") 'I have named the occurrence for 3d sketch "3D"
Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oDef.Occurrences.ItemByName("2D") 'I have named the occurrence with 2d sketch "2D"
Dim pDef1 As PartComponentDefinition
Set pDef1 = oOcc1.Definition
Dim pDef2 As PartComponentDefinition
Set pDef2 = oOcc2.Definition
Dim oSketch3d As Sketch3D
Set oSketch3d = pDef1.Sketches3D.Add
Dim oSketch3dProx As Sketch3DProxy
Call oOcc1.CreateGeometryProxy(oSketch3d, oSketch3dProx)
Dim oSketch2dProxy As PlanarSketchProxy
Call oOcc2.CreateGeometryProxy(pDef2.Sketches("Sketch1"), oSketch2dProxy) 'Name of sketch in my case "Sketch1"
Dim oEnt As SketchEntity
For Each oEnt In oSketch2dProxy.SketchEntities
    On Error Resume Next
    Call oSketch3dProx.Include(oEnt)
Next

oAsm.Update
End Sub