AutoCAD Mechanical Forum
Welcome to Autodesk’s AutoCAD Mechanical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Mechanical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programmatically create Parts and Views

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
674 Views, 4 Replies

Programmatically create Parts and Views

Good morning

we have to migrate a set of about 7000 legacy DWGs for one of our customers. The customer made this DWGs using AutoCAD and a third party application. The application works organizing the drawing in part and views in a manner similar to the way Mechanical does with the Structure feature. The application simply separates the entities on different layers, so we're able to analyze the drawing and figure out, for each entity, which is the part/view it belongs to.

We need to create programatically the part and views, but we can't find a sample (possibly c#) for achieve this.

Can you please provide a sample for create a Part and a View programmatically? Or at least point us in the right direction?

 

Thanks.

Best regards.

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Wouldn't a Lisp layer converter already do the trick?

We have one that just checks the layer/object types and sticks them in the correct Mechanical layer: hatches all in AM_8, dimensions in AM_5 and then based on our own list... move everything on layer x to layer AM_.
(for example everything on layer "profiel" to "AM_0") etc.

Besides that we also apply the Mechanical standards, read in texts etc.

More in this direction is possible... for example we're actually creating and modifying parts based on textual data in the right bottom corner block.

These routines can be applied on folders, but end results will always depend on how far you go in your code and in how far the base material has been consistently made (so the layers are actually used as they should etc).
Message 3 of 5
Anonymous
in reply to: Anonymous

Hi acwtzwegers

thanks for your answer, how do you create viewv and parts from blocks? I could create blocks and then create the views.

 

In the past there was a command AMMIGRATE for this but I'm no more able to foud it.

 

Thanks

Message 4 of 5
Anonymous
in reply to: Anonymous

At this address

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=14952981

I downloaded the Autocad Mechanical 2015 Developer Guide, in this I found an interesting sample (2D Mechanical Structure Sample Code) in VBA, I managed to translate it in C#, 

 

    [CommandMethod("AutocadAddIn_Test")]

    public void AutocadAddIn_Test()

    {

      // get the AcadApplication COM object

      AutoCAD.AcadApplication mAcadApp = (AutoCAD.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

      // get the AcadmApplication object

      AcadmAuto.AcadmApplication mAcmApp = (AcadmAuto.AcadmApplication)mAcadApp.GetInterfaceObject("AcadmAuto.AcadmApplication");

      // get the structure manager

      AcadmAuto.IMcad2DStructureMgr gMgr = mAcmApp.ActiveDocument.StructureMgr2D;

      Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

      AutoCAD.AcadDocument acadDoc = (AutoCAD.AcadDocument)doc.GetAcadDocument();

 

      Double[] center = new Double[3];

      AutoCAD.AcadCircle circle1;

      center[0] = 0;

      center[1] = 0;

      center[2] = 0;

 

      circle1 = acadDoc.ModelSpace.AddCircle(center, 10);

      long gObjId = circle1.ObjectID;

 

      string compName = "MyComponent";

      string viewName = "FirstView";

 

      AcadmAuto.McadComponentDefinition compDef;

 

      if (gMgr.HasComponentDefinition(compName, out compDef))

      {

        MessageBox.Show(compName + " already exists.");

        return;

      }

 

      AcadmAuto.McadComponentDefinition rootCompDef = gMgr.RootComponentDefinition;

      compDef = gMgr.AddNewComponentDefinition(compName);

 

      GEAuto.GeApplication gGeApp = mAcadApp.GetInterfaceObject("GE.Application");

      GEAuto.GeMatrix compGeMatrix = gGeApp.Matrix();

 

      GEAuto.GeVector compTranslation = gGeApp.Vector();

      GEAuto.GePoint startPoint = gGeApp.Point();

      GEAuto.GePoint endPoint = gGeApp.Point();

 

      endPoint.Set(10, 0, 0);

      compTranslation.Set(startPoint, endPoint);

      compGeMatrix.SetToTranslation(compTranslation);

 

      AcadmAuto.McadComponent comp;

      comp = rootCompDef.AddComponent(compDef, compGeMatrix);

 

      AcadmAuto.McadComponentView compView;

      AcadmAuto.McadComponentViewDefinition compViewDef;

      AcadmAuto.McadComponentView targetView = null;

 

      long[] entities = new long[1];

      entities[0] = gObjId;

 

      // all is Ok until here

 

      // here is where I get the error Type mismatch. Eccezione da HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)

      gMgr.AddNewComponentViewDefinition(out compViewDef, out compView, comp, compGeMatrix, null, entities, targetView, viewName);

    }

 

all works fine until the last row: when I try to create the view I get the error "Eccezione da HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)"

 

Since I can't find a solution myself, I'm trying to post it here, hoping someone may help me, with some ideas.

 

Thanks

Message 5 of 5
Anonymous
in reply to: Anonymous

Finally I've got it works.

My fault was I was using null, instead og Type.Missing 

 

So

 

gMgr.AddNewComponentViewDefinition(out compViewDef, outcompView, comp, compGeMatrix, null, entities, targetView, viewName);

 

should be

 

gMgr.AddNewComponentViewDefinition(out compViewDef, outcompView, comp, compGeMatrix, Type.Missing, entities, Type.Missing, viewName);

 

 

Nicola

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost