DirectShape with GeometryInstance and non conformal Transform
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This question relates to this one
https://forums.autodesk.com/t5/revit-api-forum/access-transform-of-a-directshape/m-p/13100704#M82239
I've created a DirectShape with GeometryInstances using the DirectShapeLibrary.
I've realized it is possible to create GeometryInstance with a transform that has non uniform scale. This is nice, since I want to visualize geometry of a custom tool with meshes and arbitrary transform matrices.
Unfortunatly the DirectShape can't be selected in 3DView only in PlanView.
Has anyone experienced this before?
Here some example code. If you don't scale BasisX everything is fine.
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class CmdTest : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var doc = commandData.Application.ActiveUIDocument.Document;
var p0 = new XYZ(-1, -1, 0);
var p1 = new XYZ(1, -1, 0);
var p2 = new XYZ(1, 1, 0);
var p3 = new XYZ(-1, 1, 0);
var line0 = Line.CreateBound(p0, p1);
var line1 = Line.CreateBound(p1, p2);
var line2 = Line.CreateBound(p2, p3);
var line3 = Line.CreateBound(p3, p0);
var loop = new CurveLoop();
loop.Append(line0);
loop.Append(line1);
loop.Append(line2);
loop.Append(line3);
var loops = new CurveLoop[] { loop };
var solid = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, 1.0);
using (var transaction = new Transaction(doc, "Create DS Box"))
{
transaction.Start();
var dsType = DirectShapeType.Create(doc, "Box", new ElementId(BuiltInCategory.OST_GenericModel));
dsType.SetShape([solid]);
var dsLib = DirectShapeLibrary.GetDirectShapeLibrary(doc);
dsLib.AddDefinitionType("Box", dsType.Id);
var transform = new Transform(Transform.Identity);
transform.BasisX *= 2; // stretch the box, non conformal
var directShape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
var geoInst = DirectShape.CreateGeometryInstance(doc, "Box", transform);
directShape.SetShape(geoInst);
directShape.SetTypeId(dsType.Id);
transaction.Commit();
}
return Result.Succeeded;
}
}
If