Inventor 2013 + VB.net API help, referencing sketch entities?

Inventor 2013 + VB.net API help, referencing sketch entities?

Anonymous
Not applicable
978 Views
1 Reply
Message 1 of 2

Inventor 2013 + VB.net API help, referencing sketch entities?

Anonymous
Not applicable

Hi Im new to Programing and attempting to teach my self some basics, I have done the My first inventor API and have been to Mod the machine. It's a big jump I am trying to make. I am looking for some assistance in terms of access to variouse levels of the COM. 

 

I have examples of part document creation that can be used for any document type ect. and how to make it the active doc. 

And also some code that works for sketch creation.

 

What i need some assistance with is making the some sketch geometry, If  I am creating a new line for example I need a sketch (so in terms of doing it inventor I create sketch then edit sketch then create line). 

 

For a program to do this I realise I need to tell the program where to sketch ect like "right click edit sketch1" 

 

However this is where my dilema comes in  I need to reference a sketch, from what i have read + a few guesses the GetReferenceKey method gives me some 

code like 214124124515 thats refers specifically to a sketch entity.

 

OK so I need to GetReferenceKey of a Planar sketch with reference key (GetReferenceKey of a planar sketch ect ect ect, you get the idea.

I will come back to this in a moment.

 

Sketches have names so I could cross reference sketches with name "sketch1"  ie GetReferenceKey of sketch with name "sketch1". 

 

So far I have not aksed a specific question because I wanted to give you some Idea of what I am thinking so you understand what I am looking for. 

 

1- is the the PropertySets -----> Property Set -----> Property the way you would access any property of any object?

 

Could some one please help me creating a command that does this cross reference so I can start making some circles and stuff, or just tell me I have got it all wrong (if thats that case). And some other method to use?

 

 

 

 

 

 

0 Likes
979 Views
1 Reply
Reply (1)
Message 2 of 2

rjay75
Collaborator
Collaborator

In answer to how to reference an object you don't need the reference key to do that unless you're storing the reference and need to be able to directly retrieve it later. Most objects will be part of an object collection that you can either go through by name or iterate through to find something.

 

For a PlanarSketch it would be, ThePartDocument.PartComponentDefinition.Sketches(idx), with idx being the index number of the sketch.

 

To find a specifically named sketch through iteration it would be:

 

Dim pDoc As PartDocument
Dim sketch1 As PlanarSketch

pDoc = ThisApplication.ActiveDocument

Dim sketches As PlanarSketches = pDoc.ComponentDefinition.Sketches

For Each s As PlanarSketch In sketches
    If s.Name = "Sketch1" Then
        sketch1 = s
        Exit For
    End If
Next

If Not sketch1 Is Nothing Then
    MessageBox.Show("Found Sketch1")
Else
    MessageBox.Show("Could not find Sketch1")
End If

 

If you want to create on the XY Plane and assign it the code would be:

 

Dim pDoc As PartDocument
Dim sketch1 As PlanarSketch

pDoc = ThisApplication.ActiveDocument

Dim sketches As PlanarSketches = pDoc.ComponentDefinition.Sketches
Dim planeXY As WorkPlane = pDoc.ComponentDefinition.WorkPlanes("XY Plane")

sketch1 = sketches.Add(planeXY) If Not sketch1 Is Nothing Then MessageBox.Show("Found a sketch named: " & sketch1.Name) Else MessageBox.Show("Could not create a sketch.") End If

 

Both of these examples are VB.Net code and will work in iLogic.

 

I would also recomment looking at the Inventor Object model. I've attached the 2013 pdf because I couldn't find a link to it.

 

Another source of samples are on git hub here: Training Material, and the Manufacturing Dev Blog

 

0 Likes