.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to insert an entity from another drawing using vb.net in stand-alone program

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
cncah
772 Views, 2 Replies

How to insert an entity from another drawing using vb.net in stand-alone program

Hello, I'm wondering how to get a point from the user to insert an entity into a drawing from another drawing using vb.net in a stand-alone program. I'm having to write this as a stand alone program because this is only a small portion of my overall program and I'm interfacing with 3 other softwares besides Autocad. I know how to do this when writing the vb program as a dll and how to do it in AutoLisp but not as a stand alone vb program. Any help would be appreciated. Thank you.

2 REPLIES 2
Message 2 of 3
Mikko
in reply to: cncah

You need to prompt the user for a point:
Dim insertionPnt = AcadDoc.Utility.GetPoint(, "Enter a point: ")

 

Then get block ref into your drawing:
Dim AcadApp As AcadApplication = CType(GetObject(, "AutoCAD.Application.?"), AcadApplication)

Dim TargetDoc As AcadDocument = AcadApp.ActiveDocument
Dim DbxDoc As Object = AcadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.?")
DbxDoc.Open("the_Source_FileName")
Dim Objects(0) As Common.AcadBlock
For Each entry As Common.AcadBlock In CType(DbxDoc.Blocks, IEnumerable)
If (Not entry.IsLayout) AndAlso (Not entry.Name.StartsWith("*")) Then
Objects(0) = entry
DbxDoc.CopyObjects(CObj(Objects), TargetDoc.Blocks)
End If
Next entry

 

Then insert block into drawing at the prompted point:
AcadDoc.ModelSpace.InsertBlock(insertionPnt, "SomeBlock", 1#, 1#, 1#, 0)

 

I haven't done this in a while but I think this is all thats needed.  Maybe somebody can give you more complete code to use but if you play around with this a bit you should be able to figure it out.  Then again, I could be way off base 🙂

Message 3 of 3
cncah
in reply to: Mikko

That worked great! Here is what worked for me:

 

Dim acadapp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
        Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument = Nothing

        Try
            acadapp = CType(GetObject(, "AutoCAD.Application"), Autodesk.AutoCAD.Interop.AcadApplication)
            acadDoc = CType(acadapp.ActiveDocument, Autodesk.AutoCAD.Interop.AcadDocument)

            If acadapp IsNot Nothing And acadDoc IsNot Nothing Then

                Dim insertionPT = acadDoc.Utility.GetPoint(, "Pick Insertion Point Between Radii At Bottom Of Pocket:")

                Dim DbxDoc As Object = acadapp.GetInterfaceObject("ObjectDBX.AxDbDocument.19")
                DbxDoc.Open("C:\Path_To_Block_Drawing.dwg")

                Dim Objects(0) As AcadBlock
                For Each entry As AcadBlock In CType(DbxDoc.Blocks, IEnumerable)
                    If (Not entry.IsLayout) AndAlso (Not entry.Name.StartsWith("*")) Then
                        Objects(0) = entry
                        DbxDoc.CopyObjects(CObj(Objects), acadDoc.Blocks)
                    End If
                Next entry

                acadDoc.ModelSpace.InsertBlock(insertionPT, "NameOfBlock", 1.0#, 1.0#, 1.0#, 0)                
            End If

        Catch InsertBlockError As Exception
            Debug.WriteLine(InsertBlockError)
        End Try

 Thank You Very Much! I was starting to write a bunch of small AutoLisp programs that I would start with:

 

acadDoc.SendCommand("_startlispcommand ")

 

This will work much better for me and not require a bunch of AutoLisp program maintenence on our network. Thanks again!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost