WorldPositionMatrix of created parts

Hello everybody,

I have a quick question about the WorldPositionMatrix of created parts. I always set the WorldPosition of the parts in the vcmx-files that I use for my Component Creators at (0/0/0). After the parts have been created in my project I grab them with a robot or transport them via one way paths. I create new parts of the same vcmx-file every 2 seconds, but I only want to change the colour of some at a specific position. I work with this code to get the position:

from vcScript import *
import vcMatrix

app = getApplication()
comp = getComponent()
weldingCreator = comp.getBehaviour("ComponentCreator3")
weldingContainer = comp.getBehaviour("ComponentContainer2")

def OnRun():    
  while True:   
    #default colour when weldingSignal false
    if(weldingSignal.Value == False):
      comp1 = app.findComponent("Welding part-1.2")
      comp2 = app.findComponent("Welding part-2.4")
  
      if comp1.getFeature("Welding part-1.2"):
        geo_feat1 = comp1.getFeature("Welding part-1.2")
        geo_cont1 = geo_feat1.Geometry
        colour = app.findMaterial('metal')

      #paint all created Welding parts-1.2
      for set in geo_cont1.GeometrySets:
        set.Material = colour
        geo_feat1.rebuild()
        app.render()
...................................................................................................................................................

      #paint created Welding parts-1.2 at (100/100/100)
      for set in geo_cont1.GeometrySets:
      
        print 'Node Position:' 
        print geo_feat1.NodePositionMatrix.P.X, geo_feat1.NodePositionMatrix.P.Y, geo_feat1.NodePositionMatrix.P.Z
        print 'Comp Position:'
        print comp1.WorldPositionMatrix.P.X, comp1.WorldPositionMatrix.P.Y, comp1.WorldPositionMatrix.P.Z  

        if( ********position that i need******** == (100/100/100)):
          set.Material = colour
          geo_feat1.rebuild()
          app.render()

...................................................................................................................................................
      if comp2.getFeature("Welding part-2.4"):  
        geo_feat2 = comp2.getFeature("Welding part-2.4")
        geo_cont2 = geo_feat2.Geometry
        colour = app.findMaterial('metal')
        for set in geo_cont2.GeometrySets:
          set.Material = colour
          geo_feat2.rebuild()
          app.render()

...

I always get the result (0/0/0). The parts are moved in the world but I’m still getting the WorldPosition of the part in the origin vcmx-file. How do I get the position of the moved parts? I really appreciate your help, thanks a lot :slight_smile:

Hy,

can you upload your simulation with the code to Debug it?

Regards
Feature

Hello captain_feature,

I would upload the file but it contains protected CAD data from the company I work at, so I’m not allowed to publish it. Sorry for that. Do u have a guess only by viewing the relevant code or how do u get the position of created and moved parts?

Thanks

Hy,

did you:

I think app.render() maybe could help?!

Regards
Feature

I already tried it with sim.update(), app.render() and comp.rebuild() before reading the WorldPositionMatrix. None of them really helped :frowning:

Hy,

did you try using “PositionMatrix” instead of “WorldPositionMatrix”?

Regards
Feature

Yes and I even tried to get the position via the feature in the component:

print comp1.WorldPositionMatrix.P.X, comp1.WorldPositionMatrix.P.Y, comp1.WorldPositionMatrix.P.Z
or
print comp1.PositionMatrix.P.X, comp1.PositionMatrix.P.Y, comp1.PositionMatrix.P.Z
or
geo_feat1 = comp1.getFeature(“Welding part-1.2”)
print geo_feat1.NodePositionMatrix.P.X, geo_feat1.NodePositionMatrix.P.Y, geo_feat1.NodePositionMatrix.P.Z

Everytime the result is (0/0/0). But when i click on the part in the modelling tab i see different values for the world position.

Greets and thanks for ur help

Okay I think I got it: To get a handle for the created parts u need the componentCreator in the same script where u read the position of the parts. Then u can use:

part = creator.create()
print part.WorldPositionMatrix.P.X, part.WorldPositionMatrix.P.Y, part.WorldPositionMatrix.P.Z

Hopefully this helps somebody. I wasted a lot of time.

1 Like