Author Topic: Loft with Editor.Command()  (Read 2223 times)

0 Members and 1 Guest are viewing this topic.

danjeff

  • Mosquito
  • Posts: 3
Loft with Editor.Command()
« on: August 08, 2022, 07:09:33 PM »
I'm looking to create a Lofted 3D solids between a number of polylines. I'm looking at the Editor.Command() method because the .Net method CreateLoftedSolid() has a limitation where the cross sections must be planar, where the user command does not. I feel like I've tried a million different combinations but I clearly don't understand how to find the inputs required for a command.
Could anybody help with the lofting inputs for Editor.Command()?

A quick bit of test code I was using is below.

Code - C#: [Select]
  1. public static void testingNode(ACDN.Document doc)
  2.                 {
  3.                     Autodesk.AutoCAD.DynamoApp.Services.DocumentContext ctx = new Autodesk.AutoCAD.DynamoApp.Services.DocumentContext(doc.AcDocument);
  4.                     Database db = ctx.Database;
  5.                     using (Transaction trans = db.TransactionManager.StartTransaction())
  6.                     {
  7.                         BlockTable blockTable = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
  8.                         BlockTableRecord btr = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  9.  
  10.                         List<Entity> ents = new List<Entity>();
  11.                         Polyline3d outputPolyline3D1 = new Polyline3d();
  12.                         Polyline3d outputPolyline3D2 = new Polyline3d();
  13.  
  14.                         outputPolyline3D1.SetDatabaseDefaults();
  15.                         btr.AppendEntity(outputPolyline3D1);
  16.                         trans.AddNewlyCreatedDBObject(outputPolyline3D1, true);
  17.  
  18.                         outputPolyline3D2.SetDatabaseDefaults();
  19.                         btr.AppendEntity(outputPolyline3D2);
  20.                         trans.AddNewlyCreatedDBObject(outputPolyline3D2, true);
  21.  
  22.                         ents.Add(outputPolyline3D1);
  23.                         ents.Add(outputPolyline3D2);
  24.  
  25.                         Point3d inputPoint1 = new Point3d(0, 0, 0);
  26.                         Point3d inputPoint2 = new Point3d(10, 0, 0);
  27.                         Point3d inputPoint3 = new Point3d(10, 10, 0);
  28.                         Point3d inputPoint4 = new Point3d(0, 10, 0);
  29.  
  30.                         Point3d inputPoint5 = new Point3d(0, 0, 10);
  31.                         Point3d inputPoint6 = new Point3d(10, 0, 10);
  32.                         Point3d inputPoint7 = new Point3d(10, 10, 10);
  33.                         Point3d inputPoint8 = new Point3d(0, 10, 10);
  34.  
  35.                         PolylineVertex3d outputPolylineVertex1 = new PolylineVertex3d(inputPoint1);
  36.                         PolylineVertex3d outputPolylineVertex2 = new PolylineVertex3d(inputPoint2);
  37.                         PolylineVertex3d outputPolylineVertex3 = new PolylineVertex3d(inputPoint3);
  38.                         PolylineVertex3d outputPolylineVertex4 = new PolylineVertex3d(inputPoint4);
  39.                         PolylineVertex3d outputPolylineVertex5 = new PolylineVertex3d(inputPoint5);
  40.                         PolylineVertex3d outputPolylineVertex6 = new PolylineVertex3d(inputPoint6);
  41.                         PolylineVertex3d outputPolylineVertex7 = new PolylineVertex3d(inputPoint7);
  42.                         PolylineVertex3d outputPolylineVertex8 = new PolylineVertex3d(inputPoint8);
  43.  
  44.                         outputPolyline3D1.AppendVertex(outputPolylineVertex1);
  45.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex1, true);
  46.                         outputPolyline3D1.AppendVertex(outputPolylineVertex2);
  47.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex2, true);
  48.                         outputPolyline3D1.AppendVertex(outputPolylineVertex3);
  49.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex3, true);
  50.                         outputPolyline3D1.AppendVertex(outputPolylineVertex4);
  51.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex4, true);
  52.                         outputPolyline3D2.AppendVertex(outputPolylineVertex5);
  53.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex5, true);
  54.                         outputPolyline3D2.AppendVertex(outputPolylineVertex6);
  55.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex6, true);
  56.                         outputPolyline3D2.AppendVertex(outputPolylineVertex7);
  57.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex7, true);
  58.                         outputPolyline3D2.AppendVertex(outputPolylineVertex8);
  59.                         trans.AddNewlyCreatedDBObject(outputPolylineVertex8, true);
  60.  
  61.                         outputPolyline3D1.Closed = true;
  62.                         outputPolyline3D2.Closed = true;
  63.  
  64.                         Autodesk.AutoCAD.ApplicationServices.DocumentCollection docColl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
  65.                         Autodesk.AutoCAD.ApplicationServices.Document testDoc = docColl.MdiActiveDocument;
  66.                         Autodesk.AutoCAD.EditorInput.Editor testEdit = testDoc.Editor;
  67.                        
  68.                         //I don't understand why "testEdit.Command()" throws invalid input
  69.                         var ss = Autodesk.AutoCAD.EditorInput.SelectionSet.FromObjectIds(ents.Select(entitiesToCreate => entitiesToCreate.ObjectId).ToArray());
  70.                         testEdit.Command("_.loft", ss, " ", "Cross sections only");
  71.  
  72.                         //This works but is not synchronous
  73.                         //testEdit.SetImpliedSelection(ents.Select(ent => ent.ObjectId).ToArray());
  74.                         //testDoc.SendStringToExecute("._loft  c ", false, false, false);
  75.                        
  76.                         trans.Commit();
  77.                     }
  78.                 }
« Last Edit: August 09, 2022, 01:57:40 PM by danjeff »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Loft with Editor.Command()
« Reply #1 on: August 09, 2022, 07:16:05 AM »
Hi,

Try this way:
Code - C#: [Select]
  1. testEdit.Command("_.loft", outputPolyline3D1.ObjectId, outputPolyline3D2.ObjectId, "", "_Cross");
Speaking English as a French Frog

danjeff

  • Mosquito
  • Posts: 3
Re: Loft with Editor.Command()
« Reply #2 on: August 09, 2022, 01:53:50 PM »
Hi,

Try this way:
Code - C#: [Select]
  1. testEdit.Command("_.loft", outputPolyline3D1.ObjectId, outputPolyline3D2.ObjectId, "", "_Cross");

Hi Gile,

Thanks for the quick answer on this. Unfortunately that doesn't appear to work either. I tried just performing a simple zoom:
Code: [Select]
testEdit.Command("_.ZOOM", ".8x");and that also gives an eInvalidInput exception.

For a little more context this is running in a dynamo zero touch node for civil 3D. Would that have an impact causing Editor.Command to fail?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Loft with Editor.Command()
« Reply #3 on: August 09, 2022, 02:20:51 PM »
I don't know much about Dynamo and Civil 3d, but Editor.Command only works in Document context (i.e. CommandMethod without the CommandFlags.Session or modal dialog).
Speaking English as a French Frog

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Loft with Editor.Command()
« Reply #4 on: August 09, 2022, 06:20:01 PM »
Editor must be available, I wrote a node to write a message on the Command Line.


I'm not sure what the problem is but ZT nodes never should dispose the transaction, so no using construction.


https://forum.dynamobim.com/t/c-how-to-create-autocad-entities/35214/12
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

danjeff

  • Mosquito
  • Posts: 3
Re: Loft with Editor.Command()
« Reply #5 on: August 10, 2022, 01:39:41 PM »
Editor must be available, I wrote a node to write a message on the Command Line.


I'm not sure what the problem is but ZT nodes never should dispose the transaction, so no using construction.


https://forum.dynamobim.com/t/c-how-to-create-autocad-entities/35214/12

Interesting. I seemingly haven't had any issues in my working nodes with disposing of a transaction, however the example shows using/disposing the DyanmoApp.Services.DocumentContext transaction causing errors where I have created a transaction within Autocad. I'm quite new to this though so I'm likely just ignorant on the topic.