get the circeledgeID from Normparts in Assembly to connect/replace in VBA

get the circeledgeID from Normparts in Assembly to connect/replace in VBA

k-p_heurig
Contributor Contributor
427 Views
6 Replies
Message 1 of 7

get the circeledgeID from Normparts in Assembly to connect/replace in VBA

k-p_heurig
Contributor
Contributor

Hello

i have a VBA Macro witch replaces Normparts but i can not set Lockrotation and i can not define the CirceledgesID

 

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oCompOccs As ComponentOccurrences

Dim oCompOcc As ComponentOccurrence

 

For Each oCompOcc In oAsmCompDef.Occurrences
If oCompOcc.ReferencedDocumentDescriptor.FullDocumentName = "C:\Vault\Normteile\de-DE\DIN 934 - A2\DIN 934 - M8 - A2.ipt" Then
Call oCompOcc.Replace("C:\Vault\Normteile\de-DE\DIN 934 - 10 - verzinkt\DIN 934 - M4 - 10 - verzinkt.ipt", False)
End If
Next

 

i also found in the Forum a Sample from (06-04-2019) for connecting Parts manually select the edges.

 

my question is  it possible to get the CircleedgeID automatikally? like

Dim oEdge1 As Edge
Set oEdge1 = Insertconnected CircleedgeID the OLDNormpart(DINXXX.IPT) is connected to in the Assembly
Dim oEdge2 As Edge
then put a NEWNormpart (DINYYY.IPT)in the Assembly and insertConnect  it Manually to an Circeledge.

Set oEdge2 = now get the insertConnect CircleedgeID of the NEWNormpart

and connect the CircledgeID  the OLDNormpart is connected to with the CirceledgeID the NEWNormpart is conected

Dim oInsert As InsertConstraint
Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)

 with Lockrotation is set

and delete the OLDNormpart

 

if this is posible i would be very happy if some one can give me an tipp where to look or even a snipped.

 

thanks a lot

0 Likes
428 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

It's a little difficult to follow what you are asking for.  It sounds like you want to be able to replace a component within an assembly, while maintaining an Insert type constraint, so that the replacement part will also be constrained the same way as the replaced part was, after the code is done.  Does that sound correct?  And to do this, you want to be able to capture the corresponding circular edge on the new component and use that to replace the circular edge reference of the old component being used in that constraint, right?  Since both components don't exist in the assembly at the same time, that will be impossible to do.  However, if you have identified the constraint object and used the available methods to isolate which of its two entities is connected to the component being replaced, before replacing the component, we will then have a chance to correct the resulting 'sick' constraint after you replace the component, as long as you have a plan to be able to identify which circular edge on the new component is the one we will need to replace the old reference in the constraint.  It is likely not going to be a simple or easy task, but may be possible, if set-up right.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

k-p_heurig
Contributor
Contributor

sorry for answer so late

iam in vaccation and do not have always access to an computer

 

but thanks a lot  for looking at my problem

 

 

It's a little difficult to follow what you are asking for. It sounds like you want to be able to replace a component within an assembly, while maintaining an Insert type constraint,
so that the replacement part will also be constrained the same way as the replaced part was, after the code is done. Does that sound correct? 

 

yes that is correct.

 

And to do this, you want to be able to capture the corresponding circular edge on the new component and use that to replace the circular edge reference of the old component being used in that constraint, right?

 

yes that is correct,

but i forgot to mention that i place up front one new part in the assembly.for getting the edgeID

 

before replacing the component, we will then have a chance to correct the resulting 'sick' constraint after you replace the component,

 

what to you mean by ,,sick,, constraint, the constraint to the old part are ok

what i want to achive is ,,LockRotaion,, after replacing  the parts

 

for just replacing the parts i can use the sample snippets , but how can i insert the ,,LockRotation,, after replacing the parts

 

greetings

kp

0 Likes
Message 4 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

The LockRotation is a boolean property of the insertconstraint.

oInsert.LockRotation = True

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 7

k-p_heurig
Contributor
Contributor

hallo

i found the following ilogic sample in the forum

i tryed to translate it into VBA

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
For Each oConst As AssemblyConstraint In oCompDef.Constraints
	If oConst.Type = kInsertConstraintObject
		Dim oName As String = oConst.Name
		oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
		On Error Resume Next
		oConst.Name = oName
	End If
Next 

 

here the VBA Code from the Ilogic sample

 

Sub nixconst()

Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument

Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = oAsm.ComponentDefinition


Dim oConst As AssemblyConstraint


For Each oConst In oCompDef.Constraints
If oConst.Type Is kInsertConstraintObject Then
Dim oName As String
Set oName = oConst.Name
oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
On Error Resume Next
oConst.Name = oName
End If
Next

End Sub

 

unfortunately there are a few Problems

 

kInsertConstraintObject = wrong typ

Set oName = oConst.Name = Objekt necessary

oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True) = Objekt supports this feature Methode not (translatet from German)

 

all the variables are picked from the Inventor API

if somebody knows what iam doing wrong

i would be very happy if i get some help

 

 

 

0 Likes
Message 6 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

I don't see the sense of the saving and restoring the name, cause it doesn't change in my tests. Anyway, converted to VBA:

Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument

Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = oAsm.ComponentDefinition

Dim oConst As AssemblyConstraint
Dim oName As String
For Each oConst In oCompDef.Constraints
    If oConst.Type = kInsertConstraintObject Then
        oName = oConst.Name
        Set oConst = oConst.ConvertToInsertConstraint2(oConst.EntityOne, oConst.EntityTwo, oConst.AxesOpposed, oConst.Distance.Value, True)
        On Error Resume Next
        oConst.Name = oName
     End If
Next

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 7 of 7

k-p_heurig
Contributor
Contributor

hello

the reason for all this is:

first

we have in the content Center a Family  Welding Nut witch is corrupted

my Idea was to create a new Welding Nut familiy in the content Center

and afterwards replace the Parts from the Corrupted Family with the new one

 

because of that many Assemblys we have with Welding Nut

i thought it a good Idea to write a makro wich replaces the Parts

AND

Put also a ,,Lockrotation,, to the Constraint.

hopefully the replaceing of the Welding Nuts wont change the BOM and the Drawing

 

Solution:

find in Vault all the assemblys with a Welding Nut

for Examble DIN 929 M8 A2 , remember all the Assembly name

open them one by one  in Inventor and run the makro

with replace it with the ,,NEW,, DIN 929 M8 A2 from a different Folder

so far its working

but the Lockrotation is the Problem

 

i found some examples in the Inventor API Help

but there you have to manually select the circle Edges witch i wonded to avoid

 

my thought was after replacing the Welding Nuts

i know the new Welding Nut and with it the contraint           ,,Imate   - Einfügen: -

witch i just have to lockrotate

 

if you have a better Idea for solving this Problem i would be very grateful to hear it

 

 

thank you very much for the VBA version

i have

,,set =,,

put on the wrong line.

 

greetings karl-peter

 

0 Likes