Create Component in 3d World using Python

Hello i am new here , i am new to Visual Component , i need help creating or importing file using Python into the 3d World , like i have 3 CAD file , each contains a specific Maschine that i want to set in a pre defined Position into the 3d World . I want that this Components are static , that mean after resetting the simulation they should stay in the position i gave .
Thank you in Advance

I did a test on cloning components in the 3D world, but the component was automatically deleted after resetting because there were some delete statements under OnReset(). If you comment or delete the statement, the components is retained. I don’t know if this is useful for you.


components_clone_test.vcmx (12.4 KB)

1 Like

Thank you , that work could you please help me know also how can i get the position of each Block , per example i mean like i want to create the block on the position (0.0.0), another block has to be after that created on (0.0.1)

If you don’t mind the component suddenly appearing in that position, you can define its position directly with a matrix.

Could you please give me an example, because i am really new , i am not sure about what Matrix are you talking

In Liuliu_jin’s example, there is already a function for matrix setting, and I have marked the specific content to make it easier for you to understand.

...
    #---------------------
    #Get the position matrix of the cloned component, usually they contain its X,Y,Z,RX,RY,RZ properties.
    #It should be noted that, ***.PositionMatrix this method obtains a component's parent coordinate frame 
    #attribute, if the parent is not specified, the default simulation world is the parent component, at this 
    #time PositionMatrix = WorldPositionMatrix.
    position_comp_clone_matrix = comp_clone.PositionMatrix
    #Get the position vector of the cloned component, here we use the property P, you can read the help 
    #file to get other properties like N,O,A,WPR, here this vector contains the X,Y,Z of the component.
    position_comp_clone_vector = position_comp_clone_matrix.P
    #Get the Z property in the vector and assign it a value to make it equivalent to the position of the parent
    #component, 100mm in the positive direction of the Z-axis, noting that it is just a numeric value when not reassigned to matrix.
    #The translateRel in method can do the same thing, you need to check vcMatrix in the help file to get it.
    value_z = position_comp_clone_vector.Z
    value_z = value_z + 100
    position_comp_clone_vector.Z = value_z
    position_comp_clone_matrix.P = position_comp_clone_vector 
    #Overall rotation 15 degrees
    position_comp_clone_matrix.rotateRelZ(15)
    #final assignment
    comp_clone.PositionMatrix = position_comp_clone_matrix
    #iteration
    copy_comp_func(comp_clone)
...

If you’re not sure what PositionMatrix is, I suggest you look it up on a maths website, it’s a maths problem, and of course, you can learn about the case by looking at vcMatrix in the help file. :melting_face: