Jump to content

How to attach the Library from the ObjectARX to VB.net


Recommended Posts

Posted

hello everybody .

 

Finally I have finished downloading the ObjectARX and the VB.net 2010 at home , so how could I attach the library from ARX to the VB.net to be able to use it directly from Vb.net ?

 

Any other more advices would be highly appreciated .

 

Thank you all .

 

Tharwat

Posted

Tharwat,

 

You do not need the ARX (C++) 'Library' for VB.NET code to function in AutoCAD. Instead, you simply need to add references to AcMgd.dll, and AcDbMgd.dll into your project.

 

** Be sure to set both of them to Copy Local = False.

 

Then be sure to add something similar to this (project dependent) prior to your Class in *.vb:

 

[color=blue]Imports [/color]Autodesk.AutoCAD.ApplicationServices
[color=blue]Imports [/color]Autodesk.AutoCAD.DatabaseServices
[color=blue]Imports [/color]Autodesk.AutoCAD.EditorInput
[color=blue]Imports [/color]Autodesk.AutoCAD.Geometry
[color=blue]Imports [/color]Autodesk.AutoCAD.Runtime

Now, any/all of your *should* work.

 

HTH

 

Edit: Also, the Object Browser is your friend. ;)

Posted

Thank you RenderMan for your reply .

 

Could you please give me a complete simple codes to allow me to copy and paste them to a new project in Vb.net and run it to see how things are going on ?

 

Because the example that is included within the link that I 've brought , I could not try it due to something wrong I could not solve .

 

 

Regards

Posted

These should get you started:

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime

Imports System
Imports System.Runtime
Imports System.Drawing

Public Class Commands

   <CommandMethod("HelloWorld")> _
   Public Sub HelloWorld()
       Dim ed = Application.DocumentManager.MdiActiveDocument.Editor
       ed.WriteMessage(vbLf & "Hello World! ")
   End Sub

   <CommandMethod("Q")> _
   Public Sub Q()
       Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
       If Application.GetSystemVariable("mbuttonpan") = 1 Then
           Application.SetSystemVariable("mbuttonpan", 0)
           ed.WriteMessage(vbLf & "MBUTTONPAN: OFF ")
       Else
           Application.SetSystemVariable("mbuttonpan", 1)
           ed.WriteMessage(vbLf & "MBUTTONPAN: ON ")
       End If
   End Sub

   ' FileSystemObject test
   <CommandMethod("FSOTEST")> _
   Public Sub FSOTEST()
       Dim FSysObj = CreateObject("Scripting.FileSystemObject")
       If FSysObj.DriveExists("C:\") = False Then
           MsgBox("C: Drive not available!")
       Else
           MsgBox("C: Drive exists!")
       End If
   End Sub

   ' GetStringFromUser tutorial
   <CommandMethod("GetStringFromUser")> _
   Public Sub GetStringFromUser()
       Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
       Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & _
                                                                     "Enter your name:")
       pStrOpts.AllowSpaces = True
       Dim pStrRes As PromptResult = acDoc.Editor.GetString(pStrOpts)
       Application.ShowAlertDialog("The name entered was: " & _
                                   pStrRes.StringResult)
   End Sub

   ' GetPointFromUser tutorial
   <CommandMethod("GetPointFromUser")> _
   Public Sub GetPointFromUser()

       ' Get the current database and start the transaction manager
       Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
       Dim acCurDb As Database = acDoc.Database
       Dim pPtRes As PromptPointResult
       Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")

       ' Prompt for the start point
       pPtOpts.Message = vbLf & "Enter the start point of the line: "
       pPtRes = acDoc.Editor.GetPoint(pPtOpts)
       Dim ptStart As Point3d = pPtRes.Value

       ' Exit if the user presses ESC or cancels the command
       If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

       ' Prompt for the end point
       pPtOpts.Message = vbLf & "Enter the end point of the line: "
       pPtOpts.UseBasePoint = True
       pPtOpts.BasePoint = ptStart
       pPtRes = acDoc.Editor.GetPoint(pPtOpts)
       Dim ptEnd As Point3d = pPtRes.Value
       If pPtRes.Status = PromptStatus.Cancel Then Exit Sub

       ' Start transaction
       Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
           Dim acBlkTbl As BlockTable
           Dim acBlkTblRec As BlockTableRecord

           ' Open model space for write
           acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
                                        OpenMode.ForRead)
           acBlkTblRec = acTrans.GetObject(acBlkTbl _
                                            (BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

           ' Define the new line
           Dim acLine As Line = New Line(ptStart, ptEnd)
           acLine.SetDatabaseDefaults()

           ' Add the line to the drawing
           acBlkTblRec.AppendEntity(acLine)
           acTrans.AddNewlyCreatedDBObject(acLine, True)

           ' Zoom to the extents or limits of the drawing
           acDoc.SendStringToExecute("._zoom _all ", True, False, False)

           ' Comit the changes and dispose of the transaction
           acTrans.Commit()
       End Using
   End Sub

   ' GetKeywordFromUser tutorial
   <CommandMethod("GetKeywordFromUser")> _
   Public Sub GetKeywordFromUser()
       Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
       Dim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")
       pKeyOpts.Message = vbLf & "Enter an option "
       pKeyOpts.Keywords.Add("Line")
       pKeyOpts.Keywords.Add("Circle")
       pKeyOpts.Keywords.Add("Arc")
       pKeyOpts.AllowNone = False
       Dim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)
       Application.ShowAlertDialog("Entered keyword: " & _
                                   pKeyRes.StringResult)
   End Sub

   ' GetIntegerOrKeywordFromUser tutorial
   <CommandMethod("GetIntegerOrKeywordFromUser")> _
   Public Sub GetIntegerOrKeywordFromUser()
       Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
       Dim pIntOpts As PromptIntegerOptions = New PromptIntegerOptions("")
       pIntOpts.Message = vbCrLf & "Enter the size or "

       ' Restrict input to positive and non-negative values
       pIntOpts.AllowZero = False
       pIntOpts.AllowNegative = False

       ' Define the valid keywords and allow Enter
       pIntOpts.Keywords.Add("Big")
       pIntOpts.Keywords.Add("Small")
       pIntOpts.Keywords.Add("Regular")
       pIntOpts.AllowNone = True

       ' Get the value entered by the user
       Dim pIntRes As PromptIntegerResult = acDoc.Editor.GetInteger(pIntOpts)
       If pIntRes.Status = PromptStatus.Keyword Then
           Application.ShowAlertDialog("Entered keyword: " & _
                                       pIntRes.StringResult)
       Else
           Application.ShowAlertDialog("Entered value: " & _
                                       pIntRes.Value.ToString())
       End If
   End Sub

   <CommandMethod("PositionApplicationWindow")> _
   Public Sub PositionApplicationWindow()

       '' Set the position of the Application window 
       Dim ptApp As Point = New Point(0, 0)
       Application.MainWindow.Location = ptApp

       '' Set the size of the Application window 
       Dim szApp As Size = New Size(400, 400)
       Application.MainWindow.Size = szApp
   End Sub

   ' HideWindowState tutorial
   <CommandMethod("HideWindowState")> _
   Public Sub HideWindowState()

       ' Hide the Application window 
       Application.MainWindow.Visible = False
       MsgBox("Invisible", MsgBoxStyle.SystemModal, "Show/Hide")

       ' Show the Application window 
       Application.MainWindow.Visible = True
       MsgBox("Visible", MsgBoxStyle.SystemModal, "Show/Hide")
   End Sub

End Class

 

** Note - This code requires references to AcMgd.dll, and AcDbMgd.dll (found in the Application directory, and set Copy Local = False), has been compiled using .NET Framework 3.5, and has been tested using Civil 3D 2011.

Posted

Thank you buddy ,

 

But here is the message that I always receive when pasting codes and hit the button Start Debugging to run the routine .

 

What was wrong with it please ?

Untitled-1.jpg

Untitled-2.jpg

Posted

In your project, rename the *.vb file (found in the Solution Explorer to the upper right) as "Commands.vb"

 

Paste the code into Commands.vb (which should be EMPTY), then save your project. At this point, you WILL see any errors listed in the error list toward the bottom of the IDE.

 

To confirm this, I have deleted everything from my personal Commands.vb and pasted in the code I posted above. I have zero errors at this time.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...