Message 1 sur 7
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Lien permanent
- Imprimer
- Signaler
Dear Mentors @_gile ,
1. I am trying to create a viewport through C# and I was testing the code available on Autodesk
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-61C22902-F63B-4204-86EC-FA37312D1B6E
2. When I run this program with AUTOCAD 2020, I get this error
3. I tried replacing "acad.exe" with "acdb23.dll" or "accoremgd.dll" and it did not work.
4. As a novice, the use of DLLIMPORT and ENTRYPOINT are both very new to me and I am really excited to learn more about it. But, at the same time I also want to know WHERE and HOW do I figure out the ENTRYPOINTs of acad.exe in my computer? Does AUTODESK have a reference on the website?
Many many thanks
Kenny
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")]
extern static private int acedSetCurrentVPort(IntPtr AcDbVport);
[CommandMethod("CreateFloatingViewport")]
public static void CreateFloatingViewport()
{
// Get the current document and database, and start a transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Paper space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0);
acDoc.Editor.SwitchToPaperSpace();
// Create a Viewport
using (Viewport acVport = new Viewport())
{
acVport.CenterPoint = new Point3d(3.25, 3, 0);
acVport.Width = 6;
acVport.Height = 5;
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acVport);
acTrans.AddNewlyCreatedDBObject(acVport, true);
// Change the view direction
acVport.ViewDirection = new Vector3d(1, 1, 1);
// Enable the viewport
acVport.On = true;
// Activate model space in the viewport
acDoc.Editor.SwitchToModelSpace();
// Set the new viewport current via an imported ObjectARX function
acedSetCurrentVPort(acVport.UnmanagedObject);
}
// Save the new objects to the database
acTrans.Commit();
}
}
Résolu ! Accéder à la solution.