Hy,
I am having troubles exploding nested blocks and getting the correct transformation to insert the parts again.
So I have this block (lets call it block A, origin = pt1) which is actually consisting of four blocks (the pink part Block B, origin pt1 and three screws block C origins pt2-pt4)
When I place this block with transormation trans1 somewhere in space, explode it and insert the parts again I never get the correct result. When I apply the trans1 again on all parts the screws are placed at pt1 of course.
When I apply the transformation of the transformation array of the explode command the screws are placed somewhere totally different in space.
Here is part of the command and the file
BMU_Test.3dm (771.4 KB)
InstanceDefinition thisBlock;
InstanceObject thisBlockInstance;
Guid thisBlockInstanceID;
RhinoObject blockElements;
ObjectAttributes attributes;
ObjectAttributes att;
Transform transArr;
Transform trans;
Plane thisPlane;
Guid thisBlockID;
InstanceObject tmpBlock;
int gr;
thisPlane = new Plane(new Point3d(500, 900, 1000), new Point3d(1, 2, 0), new Point3d(5, 6, 2));
trans = Transform.ChangeBasis(thisPlane, Plane.WorldXY);
thisBlock = doc.InstanceDefinitions.Find("BMU_TEST", true);
thisBlockInstanceID = doc.Objects.AddInstanceObject(thisBlock.Index, trans);
thisBlockInstance = doc.Objects.Find(thisBlockInstanceID) as InstanceObject;
thisBlockInstance.Explode(false, out blockElements, out attributes, out transArr);
// loop through the blockelements
gr = doc.Groups.Add();
for (int i = 0; i < blockElements.Length ; i++)
{
blockElements[i].Attributes = attributes[i];
if (blockElements[i].ObjectType == ObjectType.InstanceReference)
{
tmpBlock = blockElements[i] as InstanceObject;
att = attributes[i].Duplicate();
att.AddToGroup(gr);
thisBlockID = doc.Objects.AddInstanceObject(tmpBlock.InstanceDefinition.Index, transArr[i], att);
}
}
// loop through the blockelements
gr = doc.Groups.Add();
for (int i = 0; i < blockElements.Length; i++)
{
blockElements[i].Attributes = attributes[i];
if (blockElements[i].ObjectType == ObjectType.InstanceReference)
{
tmpBlock = blockElements[i] as InstanceObject;
att = attributes[i].Duplicate();
att.AddToGroup(gr);
thisBlockID = doc.Objects.AddInstanceObject(tmpBlock.InstanceDefinition.Index, trans, att);
}
}
// loop through the blockelements
gr = doc.Groups.Add();
for (int i = 0; i < blockElements.Length; i++)
{
blockElements[i].Attributes = attributes[i];
if (blockElements[i].ObjectType == ObjectType.InstanceReference)
{
tmpBlock = blockElements[i] as InstanceObject;
att = attributes[i].Duplicate();
att.AddToGroup(gr);
thisBlockID = doc.Objects.AddInstanceObject(tmpBlock.InstanceDefinition.Index, Transform.Multiply(trans, transArr[i]), att);
}
}
RhinoDoc.ActiveDoc.Objects.Lock(thisBlockInstance, true);