Author Topic: Invoke ObjectARX function goes wrong  (Read 2863 times)

0 Members and 1 Guest are viewing this topic.

Bert

  • Guest
Invoke ObjectARX function goes wrong
« on: September 02, 2014, 06:06:32 AM »
Hello fella's !

I'm working my way around inserting a Paper Space viewport, and I'm using the code available in the AutoCAD documentation :
http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-61C22902-F63B-4204-86EC-FA37312D1B6E


Code - Visual Basic: [Select]
  1.  
  2. <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
  3.  EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")> _
  4.     Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As IntPtr) As IntPtr
  5.     End Function
  6.  
  7.     <CommandMethod("CreateFloatingViewport")> _
  8.     Public Sub CreateFloatingViewport()
  9.         '' Get the current document and database, and start a transaction
  10.        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  11.         Dim acCurDb As Database = acDoc.Database
  12.  
  13.         Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  14.             '' Open the Block table for read
  15.            Dim acBlkTbl As BlockTable
  16.             acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
  17.                                          OpenMode.ForRead)
  18.  
  19.             '' Open the Block table record Paper space for write
  20.            Dim acBlkTblRec As BlockTableRecord
  21.             acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), _
  22.                                             OpenMode.ForWrite)
  23.  
  24.             '' Switch to the previous Paper space layout
  25.            Application.SetSystemVariable("TILEMODE", 0)
  26.             acDoc.Editor.SwitchToPaperSpace()
  27.  
  28.             '' Create a Viewport
  29.            Using acVport As Viewport = New Viewport()
  30.                 acVport.CenterPoint = New Point3d(3.25, 3, 0)
  31.                 acVport.Width = 6
  32.                 acVport.Height = 5
  33.  
  34.                 '' Add the new object to the block table record and the transaction
  35.                acBlkTblRec.AppendEntity(acVport)
  36.                 acTrans.AddNewlyCreatedDBObject(acVport, True)
  37.  
  38.                 '' Change the view direction
  39.                acVport.ViewDirection = New Vector3d(1, 1, 1)
  40.  
  41.                 '' Enable the viewport
  42.                acVport.On = True
  43.  
  44.                 '' Activate model space in the viewport
  45.                acDoc.Editor.SwitchToModelSpace()
  46.  
  47.                 '' Set the new viewport current via an imported ObjectARX function
  48.                acedSetCurrentVPort(acVport.UnmanagedObject)
  49.             End Using
  50.  
  51.             '' Save the new objects to the database
  52.            acTrans.Commit()
  53.         End Using
  54.     End Sub
  55.  

Line 48 calls acedSetCurrentVPort that results in the following error : (see attachment)

Any ideas how I can fix this ?

Bert

  • Guest
Re: Invoke ObjectARX function goes wrong
« Reply #1 on: September 02, 2014, 07:53:07 AM »
Found the problem by running a dependancy walker on my AutoCAD 2015 64bit acad.exe and found that in following code :

Code - Visual Basic: [Select]
  1. <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
  2.  EntryPoint:="?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")> _
  3.     Public Shared Function acedSetCurrentVPort(ByVal AcDbVport As IntPtr) As IntPtr
  4.     End Function

a) "acad.exe" needs to be "accore.dll"
and
b) the EntryPoint "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z" needs to be
    "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PEBVAcDbViewport@@@Z"

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Invoke ObjectARX function goes wrong
« Reply #2 on: September 02, 2014, 01:06:16 PM »
Hi,

It seems to me you do not need to P/Invoke acedSetCurrentVPort.
Just set the "CVPORT" system variable to the newly created viewport ID number:

Code - C#: [Select]
  1. // Set the new viewport current via the "cvport" sysvar
  2. Application.SetSystemVariable("cvport", acVport.Number);
« Last Edit: September 02, 2014, 03:03:05 PM by gile »
Speaking English as a French Frog

Bert

  • Guest
Re: Invoke ObjectARX function goes wrong
« Reply #3 on: September 03, 2014, 02:10:16 AM »
Bonjour Gile !

Merci pour votre réponse,

I've tried
Code: [Select]
Application.SetSystemVariable("cvport", acVport.Number)but it has allways given me an 'eInvalidInput' error .. the acedSetCurrentVPort call I use seems to have no trouble ?

Greetings from Belgium