How to get the transform (position) of a block instance object in C++?

blocks

(Alex) #1

How exactly do I get the position of a block instance object, which doesn’t contain any geometry in itself and holds other sub-objects ?


#2

The block instance is represented by the CRhinoInstanceObject.
With the method InstanceXform() you get the transformation of this block.


(Alex) #3

Hi @dsw, nice to see you here :slight_smile:

Thanks for your quick reply!

So, the ON_Xform object that I get from the InstanceXform(), has various methods regarding the object’s transformation.

What I need is just X, Y, Z axes information of the object.

Is Translation() method the way to go? I will be checking it out, but it would help me to save time if you knew the exact way to get the data I want.

Thanks!


(Dale Fugier) #4

Hi @alexian007,

Given a CRhinoInstanceObject object, you can calculate it’s insertion point like this:

const CRhinoInstanceObject* iref_object = ...

ON_3dPoint point = ON_3dPoint::Origin;
point.Transform(iref_object->InstanceXform());

// TODO: do something with point.

– Dale


(Alex) #5

Thanks @dale, that helps, but it is still not giving me the results that I want :frowning:


(jesterKing) #6

The point will contain the location of the instance - the translation.

Ah, but you probably also want the rotation I guess so that you can create the axis info.


(Nathan 'jesterKing' Letwory) #7

@alexian007, I have updated the changequeue sample to use the ON_3dPoint method shown by @dale to get the position. I also do something similar with the z-axis. This gives you a new z-axis for the block instance.

A few lines down there I also print the entire transform.

You can use the sample with the attached RHP and 3DM for testing

SampleRdkChangeQueue.rhp (166.5 KB, built against 6SRC13, can rebuild if needed).

SampleRdkChangeQueue.rhp (169 KB, compiled against 6SR0).

SampleRdkChangeQueue.3dm (32.5 KB)


If I have a mesh, how do I find out to which block instance it belongs? Is it possible?
(Dale Fugier) #8

Hi @alexian007,

Before we throw out any more speculation, perhaps you can explain what this means to you? What problem are you trying to solve?

– Dale


(Alex) #9

Hey @dale, the situation I am having is:

  1. Export the mesh of an object into another file format, for another 3d software.
  2. When I export a normal object, it works fine.
  3. But, when exporting block objects, the duplicated block objects appear on the same location as the original.
  4. So I am trying to modify the mesh’s vertices to get the correct position.

To show you, this is the model in Rhino. (The highlighted section is of all block instances. Some are unique while others are duplicates of one another) :

And, the result after exporting it is this:

What is happening here is that all the duplicated block instances all appear on top of one another, I have marked a section as 1 to show you that 2 was underneath it. Basically, it is taking up the same location as the original block object’s position.

So, this was why I wanted to apply the block instance position to the mesh.

So any thoughts you have regarding this?


(Nathan 'jesterKing' Letwory) #10

Does this mean the viewer you are using does not have the concept of mesh instancing?


(Dale Fugier) #11

How are you generating instance object meshes?

Can you review my reply to @binigya and let me know if this helps?

– Dale