AcadApplication

AcadApplication

Anonymous
Not applicable
1,636 Views
4 Replies
Message 1 of 5

AcadApplication

Anonymous
Not applicable
je cherche un code en c # qui permet de tester si autocad est ouvert pour ne pas le relancer et récupérer le model space.

la commande " AcadApplication app = new AcadApplication()" permet de lancer autocad mais je veux éliminer cette étape et utiliser mon model space.

voici le code que je veux le modifier

using System;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
//using App = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(ClassLibrary.civiClass))]

namespace ClassLibrary
{
///
/// Summary description for civiClass.
///

public class civiClass
{
[CommandMethod("line")]
public void line() // This method can have any name
{

AcadApplication app = new AcadApplication();

AcadDocument doc1 = app.ActiveDocument;


//This example adds a line in model space


AcadLine lineObj;

double[] startPoint = new double[3];

double[] endPoint = new double[3];


//Define the start and end points for the line

startPoint[0] = 1; startPoint[1] = 1; startPoint[2] = 0;

endPoint[0] = 50; endPoint[1] = 200; endPoint[2] = 0;

//Create the line in model space

lineObj = doc1.ModelSpace.AddLine(startPoint, endPoint);


app.Application.Visible = true;

doc1.Regen(AcRegenType.acAllViewports);

app.ZoomAll();

}
}
}

merci
0 Likes
1,637 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
i answer in english:

if i understand you want to start your macro from your already open autocad session.

first you must create a dll project, not executable, then compile and in autocad use the netload command and select the compiled dll. Then you can start your marco
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi,
I have the same problem.
I'm making a stand alone .net programm by using the Autodesk.AutoCAD.Interop
This wil allways start a new acad session.

mAcadApp = New AcadApplication

How can I become an object of the existing acad session in an external programm?
Kind regards
0 Likes
Message 4 of 5

Anonymous
Not applicable
System.Runtime.InteropServices.Marshal.GetActiveObject()

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:[email protected]...
Hi, I have the same problem. I'm making a stand alone .net programm by using the Autodesk.AutoCAD.Interop This wil allways start a new acad session. mAcadApp = New AcadApplication How can I become an object of the existing acad session in an external programm? Kind regards
0 Likes
Message 5 of 5

Anonymous
Not applicable
Vous pouvez ajouter:

{color:#0000ff}using{color} System.Runtime.InteropServices;

et

Autodesk.AutoCAD.Interop.AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
0 Likes