I’m using HiddenLineDrawing to create an elevation projection of a model, and in the process would like to add wireframes of a predetermined scale and size to the created projection lines. After selecting the model, I use the mouse to pick up a point as the base point for the elevation projection generation and calculate the location of the wireframe generation using the Boundingbox.Min and Boundingbox.Center of the projected line. However, during the generation process, I found that the center point of the Boundingbox always appears near the midpoint of the line connecting the center point of the original model and the center point of the elevation projection, and I can’t figure out why the generated wireframe is related to the position of the original model.
Here is my code
make2d
public List<Curve> Run(RhinoDoc doc, out List<string> layer_fullpaths)
{
layer_fullpaths = new List<string>();
if (this.building_ref == null)
{
return null;
}
//make2d
var hld = HLD(building_ref, view, doc);
var flatten = Trans(hld, location);
var curves = new List<Curve>();
layer_fullpaths = new List<string>();
foreach (var hld_curve in hld.Segments)
{
if (hld_curve.ParentCurve == null || hld_curve.ParentCurve.SilhouetteType == SilhouetteType.None)
continue;
var crv = hld_curve.CurveGeometry.DuplicateCurve();
if (crv != null)
{
crv.Transform(flatten);
if (hld_curve.SegmentVisibility == HiddenLineDrawingSegment.Visibility.Visible)
{
curves.Add(crv);
var tag = hld_curve.ParentCurve.SourceObject.Tag;
var layerFullPath = tag.ToString();
layer_fullpaths.Add(layerFullPath);
}
}
else
RhinoApp.WriteLine("noline");
}
return curves;
}
Add wireframes
public static void AddFrame(List<Curve> curves,int PicScale,string drawingsize,bool IsHorizontal, RhinoDoc doc)
{
var bbox = new BoundingBox();
foreach (var curve in curves)
{
var b = curve.GetBoundingBox(Rhino.Geometry.Plane.WorldXY);
bbox.Union(b);
}
var ptMin = bbox.Min;
var ptMax = bbox.Max;
doc.Objects.AddPoint(ptMin);
doc.Objects.AddPoint(ptMax);
UnitSystem unitSystem = doc.ModelUnitSystem;
double coefficient;
if (unitSystem == UnitSystem.Meters)
{
coefficient = 0.001;
}
else if (unitSystem == UnitSystem.Millimeters)
{
coefficient = 1;
}
else if(unitSystem == UnitSystem.Centimeters)
{
coefficient = 0.01;
}
else
{
coefficient = 0;
RhinoApp.WriteLine("当前文件的单位制不是米或毫米或厘米。");
}
Point3d pt2;
if (IsHorizontal==true)
{
pt2 = new Point3d(ptMin.X + 841 * coefficient, ptMin.Y + 594 * coefficient, ptMin.Z);
}
else
{
pt2 = new Point3d(ptMin.X + 594 * coefficient, ptMin.Y + 841 * coefficient, ptMin.Z);
}
Point3d boxcenter = bbox.Center;
Rectangle3d rect = new Rectangle3d(Rhino.Geometry.Plane.WorldXY, ptMin, pt2);
Point3d rectcenter = rect.Center;
var trans = Transform.Translation(boxcenter - rectcenter);
rect.Transform(trans);
var scale = Transform.Scale(boxcenter, PicScale);
Circle circle = new Circle(boxcenter, PicScale);
doc.Objects.AddCircle(circle);
var brep = bbox.ToBrep();
var id = doc.Objects.AddBrep(brep);
rect.Transform(scale);
doc.Objects.AddRectangle(rect);
}
Generate
var f = new FElevation(buildings, location);
var name = ViewList_Combobox.Text;
var Selectedview = FElevation.GetView(name, RhinoDoc.ActiveDoc);
f.view = Selectedview;
var curves = f.Run(RhinoDoc.ActiveDoc, out List<string> layer_fullpaths);
var parentlayer = FElevation.CreateParentLayer(RhinoDoc.ActiveDoc);
for (int i = 0; i < curves.Count; i++)
{
var layerindex = FElevation.CreateHierarchyLayers(layer_fullpaths[i], RhinoDoc.ActiveDoc, parentlayer);
var attribute = new ObjectAttributes();
attribute.Visible = true;
attribute.LayerIndex = layerindex;
//RhinoApp.WriteLine(attribute.LayerIndex.ToString());
var id = RhinoDoc.ActiveDoc.Objects.AddCurve(curves[i], attribute);
}
FElevation.GenerateOutLine(curves, RhinoDoc.ActiveDoc);
FElevation.AddFrame(curves,Convert.ToInt32(FrameScale.Text),FrameSize_ComboBox.SelectedItem.ToString(),(bool)Horizontal_Frame.IsChecked, RhinoDoc.ActiveDoc);
this.Close();
RhinoDoc.ActiveDoc.Views.Redraw();