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.
Solved! Go to Solution.
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
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
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