Set the offset of component to zero and ground them

Set the offset of component to zero and ground them

Ezekiel12
Collaborator Collaborator
459 Views
1 Reply
Message 1 of 2

Set the offset of component to zero and ground them

Ezekiel12
Collaborator
Collaborator

Hi,

I found really nice and useful piece of code that sets the offset of components to zero and ground them. I am now trying to change it to do it only for one part in assembly (that I specifically choose in code). So for example, do this only for component "123A:1". And I am failing miserably so far. Does anyone know?

 

Original code:

http://adndevblog.typepad.com/manufacturing/2014/10/set-the-offset-of-components-to-zero-and-ground-...

 

Dim doc As AssemblyDocument
doc = ThisApplication.ActiveDocument

Dim tr As TransientGeometry
tr = ThisApplication.TransientGeometry

Dim occ As ComponentOccurrence
For Each occ In doc.ComponentDefinition.Occurrences
  ' If it's suppressed we cannot do
  ' anything with it
  If Not occ.Suppressed Then
    Call occ.SetTransformWithoutConstraints( _
      tr.CreateMatrix())
    occ.Grounded = True
  End If
Next

 

0 Likes
Accepted solutions (1)
460 Views
1 Reply
Reply (1)
Message 2 of 2

Ezekiel12
Collaborator
Collaborator
Accepted solution

Well I finally got it to work 🙂

 

Dim tr As TransientGeometry
tr = ThisApplication.TransientGeometry

Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Component:")

If (Not entity Is Nothing) And _
(TypeOf entity Is ComponentOccurrence) Then
  If Not entity.Suppressed Then
   	 		Call entity.SetTransformWithoutConstraints( _
    	  	tr.CreateMatrix())
   	 		entity.Grounded = True
	End If
End If