How to create multi insert in API/

How to create multi insert in API/

Anonymous
Not applicable
1,774 Views
7 Replies
Message 1 of 8

How to create multi insert in API/

Anonymous
Not applicable

Hi,

 

I need to create an API to do multiple inserts. Has anyone already done, or have any idea how to do it?

 

Thanks

0 Likes
Accepted solutions (1)
1,775 Views
7 Replies
Replies (7)
Message 2 of 8

bshbsh
Collaborator
Collaborator

What do you mean by inserts? Insert constraints?

0 Likes
Message 3 of 8

Jef_E
Collaborator
Collaborator

@Anonymous wrote:

Hi,

 

I need to create an API to do multiple inserts. Has anyone already done, or have any idea how to do it?

 

Thanks


Are you going to create an API? For inventor? Please let me know when you are done? Just kidding...

 

 

Please use a better question and show some effort.. you say I'm going to make this but please someone else do this for me? And the subject is not clear at all..

 

Assuming you want to insert a part into an assembly. Youre question should be more like:

 

Spoiler

 

Hello, I'm trying to use the Inventor API to insert multiple occurrences into the active assembly. I have read the API and found this sample for adding occurrence.

 

Public Sub AddOccurrence()
    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Set a reference to the transient geometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    Set oMatrix = oTG.CreateMatrix

    ' Set the rotation of the matrix for a 45 degree rotation about the Z axis.
    Call oMatrix.SetToRotation(3.14159265358979 / 4, _
                            oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))

    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    Set oOcc = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
End Sub

My question now is, how can I use this code to place the same occurrence multiple times?

 

 

All assuming that you are talking about inserting occurrences into assembly.

 

If I could down-vote as I suggested in the ideastation this question would be definitely a BAD question.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 4 of 8

Anonymous
Not applicable

Bshbsh.

 

Yes, it's exactly as you said.

 

Jef_E

 

If I could not explain the question, I think it would be nicer if you answered the topic commenting on your questions. The way you reported is not from someone who has intension to help, because I believe that the purpose of this forum is to do just that.

 

What I would really like to do is an API for Inventor, which has the function of making multiple inserts, as the example below.

 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=7927536498261408960&appLang=en&os=Win32_64

0 Likes
Message 5 of 8

Jef_E
Collaborator
Collaborator
Accepted solution

@Anonymous wrote:

Bshbsh.

 

Yes, it's exactly as you said.

 

Jef_E

 

If I could not explain the question, I think it would be nicer if you answered the topic commenting on your questions. The way you reported is not from someone who has intension to help, because I believe that the purpose of this forum is to do just that.

 

What I would really like to do is an API for Inventor, which has the function of making multiple inserts, as the example below.

 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=7927536498261408960&appLang=en&os=Win32_64


Sorry if you feel offended, but that I am here everyday to answer questions and find solutions to my own problems. The problem is that there are 90% people that are asking for a handed solution and 10% that are looking to learn and show some effort. I'm getting really tired of this. Those 90% are most of the time not even thankful for the help.

 

As I see someone Kudo'd my post above so i'm not the only one.

 

But that aside, now my contribution to this post.

 

  1. You don't want to do an API, you want to use the API to create a tool, so I suggest you read it.
  2. If you read the API you would have found this example..

 

AssemblyConstraints.AddInsertConstraint Method

AssemblyConstraints.AddInsertConstraint Method

Parent Object: AssemblyConstraints

Description

Method that creates a new insert assembly constraint.

Syntax

AssemblyConstraints.AddInsertConstraint( EntityOne As Object, EntityTwo As Object, AxesOpposed As Boolean, Distance As Variant, [BiasPointOne] As Variant, [BiasPointTwo] As Variant ) As InsertConstraint

Parameters

Name Description
EntityOne Object that defines the first object. This object is a circular edge.
EntityTwo Object that defines the second object. This object is a circular edge.
AxesOpposed Input Boolean that specifies whether the direction of the axes of the input entities are in the same direction or opposed. A value of True indicates they are opposed.
Distance Input Variant that defines the offset between the two input entities. This can be either a numeric value or a string. A parameter for this value is created and the supplied string or value is assigned to the parameter. If a value is input, the units are centimeters. If a string is input the units can be specified as part of the string or will default to the current length units of the document.
BiasPointOne Optional input object that is used help in determining the initial position of the occurrence. The occurrences are repositioned in an attempt to make the two bias points coincident. This provides some general control over the position of the occurrence when it isn't being controlled by another constraint. An example of when the bias points are useful is the case when the first constraint on a part is a mate constraint. In the case where the mate is between two planes, the parts can be positioned anywhere along the infinite plane that defines their mating contact. Using the bias points you can define the position of the two occurrences, relative to each other. If a bias point is not given, one is calculated that is at the center of the parameter range of the input entity.
BiasPointTwo Optional input object that is used help in determining the initial position of the occurrence. The occurrences are repositioned in an attempt to make the two bias points coincident. This provides some general control over the position of the occurrence when it isn't being controlled by another constraint. An example of when the bias points are useful is the case when the first constraint on a part is a mate constraint. In the case where the mate is between two planes, the parts can be positioned anywhere along the infinite plane that defines their mating contact. Using the bias points you can define the position of the two occurrences, relative to each other. If a bias point is not given, one is calculated that is at the center of the parameter range of the input entity.

Samples

Name Description
Add assembly insert constraint This sample demonstrates the creation of an assembly insert constraint.

 

Add assembly insert constraint API Sample

Add assembly insert constraint API Sample

Description

This sample demonstrates the creation of an assembly insert constraint.

Code Samples

VBA Sample Code

Before running the sample, you need to open an assembly that contains at least two parts. Select circular edges on the two parts that will be used for the constraint and run the sample code. (Set the priority of the Select command and use the Shift-Select to select multiple edges.)

Public Sub InsertConstraint()
    ' Set a reference to the assembly component definintion.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
    
    ' Validate the correct data is in the select set.
    If oSelectSet.Count  2 Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    If Not TypeOf oSelectSet.Item(1) Is Edge Or Not TypeOf oSelectSet.Item(2) Is Edge Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    ' Get the two edges from the select set.
    Dim oEdge1 As Edge
    Dim oEdge2 As Edge
    Set oEdge1 = oSelectSet.Item(1)
    Set oEdge2 = oSelectSet.Item(2)
 
    ' Create the insert constraint between the parts.
    Dim oInsert As InsertConstraint
    Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)
End Sub


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 6 of 8

Anonymous
Not applicable

I completely understand your anger, because I do not get satisfied either when I'm looking for examples or similar situations and find nothing.

The example you suggested is almost what I need!

 

Thanks Jef_E

0 Likes
Message 7 of 8

Jordan_F.
Participant
Participant

I am very new to VBA as I just started doing research and trying to some basic code to understand it to begin with. 

 

I found the code you listed for the constrain example within the help tab, and tried to run it while I have a project open with two round edges selected and I get this error below. I am not sure what to fix as it is an example code and I am just trying to understand how to fix it, but I cannot find a reason it will not run.

 

VBA.png

0 Likes
Message 8 of 8

Anonymous
Not applicable

I have been analyzing the help code and realized that it is missing an equal sign.

Look:

If oSelectSet.Count = 2 Then

0 Likes