I am importing geometry from .dwg file via a c# script since I don’t want to open file in Rhino as this script will be running headless later.
Problem that I am facing is that I cannot seem to unwrap the blocks within the referenced geometry. I have tried both Human and eleFront but not working as you can see eblow.
Should be possible to unwrap/explode within the first c# component or in a secondary component, either would work. Any assistance in this would be greatly appreciated. sample files attached.
I’m expecting the reference class to only contains the original block guid id and a transformation (+ some simple attribute of the istance…)
You probably won’t be able at all to “explode the block” in another component, as you are missing the original document where the original block is.
You must do it where you also have access to the original document. The first script.
private void RunScript(string path, ref object geometry, ref object layerNames)
{
using( var doc = Rhino.RhinoDoc.CreateHeadless(null)){
doc.Import(path);
var geometryList = new System.Collections.Generic.List<GeometryBase>();
var names = new System.Collections.Generic.List<string>();
foreach(Rhino.DocObjects.RhinoObject obj in doc.Objects){
if(obj.Geometry.ObjectType.ToString() == "InstanceReference"){
InstanceReferenceGeometry irg = (InstanceReferenceGeometry) obj.Geometry.Duplicate();
Transform tra = irg.Xform;
foreach(Rhino.DocObjects.RhinoObject obj2 in doc.InstanceDefinitions.FindId(irg.ParentIdefId).GetObjects()){
GeometryBase geo = obj2.Geometry.Duplicate();
geo.Transform(tra);
geometryList.Add(geo);
var layer = doc.Layers[obj2.Attributes.LayerIndex];
names.Add(layer.FullPath);
}
}else{
geometryList.Add(obj.Geometry.Duplicate());
var layer = doc.Layers[obj.Attributes.LayerIndex];
names.Add(layer.FullPath);
}
}
geometry = geometryList;
layerNames = names;
}
}
Block InstanceDefinition (not InstanceReference) are simply defined around WorldXYZ 0,0,0 origin.
If you want the insertion point, just create a 0,0,0 point and transform it with that “tra” transformation.
You can do the same thing with a simple XY plane and transform that too (but remember that a plane will not store all the other shearing and scaling information that you can have in a transform/block).