+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2010
    Posts
    37

    Default Problem with inserting block in VB: Making object from calculated coordinates

    Registered forum members do not see this ad.

    Hi,

    I want to add a block with vb.net in autocad in the middle of a line. The line also has to be drawn so I make the user click on the start and end point of the line.

    I calculate from those points the midpoint. Then there is a problem to add the block on the calculated midpoint.

    Code:
    
    Dim startpunt AsObject
    Dim eindpunt AsObject
    Dim midden AsObject
    Dim inspectieput AsAcadObject
    Dim putnummer AsAcadObject
    Dim dekselhoogte AsAcadObject
    Dim aanlegjaar AsAcadBlock
    Dim strenginfo AsAcadBlock
    Dim streng AsAcadObject
    Dim attributen AsObject
    Dim I AsInteger
    Dim attribuutnaam AsString
    
     
    ' Get the first point without entering a base point
    startpunt = ThisDrawing.Utility.GetPoint(, "What is the beginning of the line?: ")
    eindpunt = ThisDrawing.Utility.GetPoint(, "What is the end of the line?: ")
    midden(0) = (startpunt(0) + eindpunt(0)) / 2
    midden(1) = startpunt(1) / 2 + eindpunt(1) / 2
    midden(2) = startpunt(2) / 2 + eindpunt(2) / 2
    If CBXbestaandstreng.Checked = TrueThen
    Else
    streng = ThisDrawing.ModelSpace.AddLine(startpunt, eindpunt)
    aanlegjaar = ThisDrawing.ModelSpace.InsertBlock(midden, "C:\block 1.dwg", 1, 1, 1, 0)
    end if
    Next
    I = Nothing
    attributen = Nothing
    attribuutnaam = Nothing
     
    EndIf
     
    
    Anyone ideas?

  2. #2
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,188

    Default

    This resembles VBA more than VB.NET. How is this code snippet written, in the VBA editor? Visual Studio? Will it be part of a DLL, loaded via AutoCAD’s NETLOAD command? Or, perhaps, made as an EXE, interfacing with AutoCAD via Autodesk.AutoCAD.Interop?



    The best advice we could give is based on how we expect the code to be compiled.

  3. #3
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2010
    Posts
    37

    Default

    Thanks for your answer.

    It is written in Visual Studio. With the netload command you load the DLL and after that you can use this command.

  4. #4
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,188

    Default

    Unfortunately, I don’t have a lot of experience using Interop - but, what if you changed this line to:



    Code:
    Dim aanlegjaar As AcadBlockReference


    Presumably, this project is a VBA to VB.NET migration. If it is, this would certainly be the most direct translation.



    The .NET API has additional capabilities for this (and many other) tasks. Time is well spent investigating pure .NET (Managed ARX) if the code is destined to run via netload.

  5. #5
    Full Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2010
    Posts
    37

    Default

    Hi thanks for your reaction. Indeed it is a VBA to VB.NET migration. I tried the suggestion you gave and it didn´t solve anything. I think it has to do with

    Code:
    Dim midden AsObject
    
    But I dont know how that should be. I hope you know.

  6. #6
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,762

    Default

    Perhaps it would be prudent for us to back up for a moment, given that this is a migration from VBA --> VB.NET to make sure some of the basics are covered first?

    This post may have some useful links to make sure that you have all of the necessary applications, and support files for coding with Visual Studio for your version of AutoCAD:

    Quote Originally Posted by RenderMan View Post
    In the short-term, have you installed the appropriate VBA Enabler for your version?

    Thinking more long-term, consider porting your code to VB.NET - You'll need Visual Studio 2010 (I use Express), the appropriate ObjectARX SDK(s), and I recommend you also use the current Wizard for properly debugging (when using Express).
    Once you've got all of that established, you'll want to (I think), be able to debug... presuming you're using Visual Studio 2010 Express, this post may come in handy:

    Quote Originally Posted by RenderMan View Post
    <snip>

    ... Consider adding a Script to your .NET project.

    Open a blank text file (Notepad?), and add the following:

    Code:
    netload "FileName.dll"
    ... Save this file to your .NET project directory with a .SCR file extension. For this example, we'll use "autoNetload.scr" but you can use any name you like.

    Next, in your .NET project, go to > Project's Properties > Debug Tab > Start Options > Add this:

    Code:
    /b "VisualStudioProjectFilePath\autoNetload.scr"
    Now Debug using Visual Studio... Tada! Your debug compiled .DLL was just NETLOADed automagically. Lemon Squeezy.



    ** Note- The reason that the script can load the DLL without providing a full file path is due to the fact that "Drawing1.dwg" is opened in the ..\bin\Debug\ folder. To confirm, simply try (getvar 'dwgprefix) at the command line.
    Separately, you may at some point want to code in Visual Studio (Express?) an application that checks for an existing instance of AutoCAD to either GetObject, or CreateObject, in which case this post may be of help:

    ** Note - This example uses an Excel Application Object, but can easily be adapted to Get/Create an AutoCAD Application Object.

    Quote Originally Posted by RenderMan View Post
    Sounds like you need to check for an active process, prior to creating a new instance.

    Here's a VB.NET snippet from one of my projects, for you to pull from:

    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports Microsoft.Office.Interop
    
    Imports System.Diagnostics
    Imports System.IO
    
    Module FOO
    
        Sub Excel_Foo()
    
            Dim xlApp As Excel.Application
    
            Try
                ' Look for an existing process, if available getObject
                If Process.GetProcessesByName("Excel").Length > 0 Then
                    xlApp = CType(GetObject(, "Excel.Application"), Excel.Application)
                ' Else createObject
                Else
                    xlApp = New Excel.Application
                End If
    
                ' <-- Do something
    
            Catch ex As Exception
    
            Finally
                xlApp = Nothing
    
        End Sub
    
    End Module
    HTH
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD® 2014, and Civil 3D® 2014 Certified Professional | Autodesk® Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  7. #7
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,762
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD® 2014, and Civil 3D® 2014 Certified Professional | Autodesk® Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  8. #8
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,188

    Default

    Registered forum members do not see this ad.

    Try this:

    Code:
        <CommandMethod("BatM")> _
        Public Sub BlockAtMid()
            Dim startpunt() As Double = New Double() {0.0, 0.0, 0.0}
            Dim eindpunt() As Double = New Double() {0.0, 0.0, 0.0}
            Dim midden() As Double = New Double() {0.0, 0.0, 0.0}
            Dim aanlegjaar As AcadBlockReference
            Dim streng As AcadLine
            Dim ThisDrawing As AcadDocument = Autodesk.AutoCAD.ApplicationServices.Application. _
                    DocumentManager.MdiActiveDocument.AcadDocument
     
            ' Get the first point without entering a base point
            startpunt = ThisDrawing.Utility.GetPoint(, "What is the beginning of the line?: ")
            eindpunt = ThisDrawing.Utility.GetPoint(startpunt, "What is the end of the line?: ")
            midden(0) = (startpunt(0) + eindpunt(0)) / 2
            midden(1) = startpunt(1) / 2 + eindpunt(1) / 2
            midden(2) = startpunt(2) / 2 + eindpunt(2) / 2
            streng = ThisDrawing.ModelSpace.AddLine(startpunt, eindpunt)
            aanlegjaar = ThisDrawing.ModelSpace.InsertBlock(midden, "C:\block 1.dwg", 1, 1, 1, 0)
        End Sub 

Similar Threads

  1. Making of Dynamic block problem
    By Qonfire in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 28th Jun 2011, 02:08 am
  2. Inserting Block problem
    By happyunited in forum AutoCAD General
    Replies: 1
    Last Post: 26th Mar 2010, 04:41 pm
  3. Help with Inserting Coordinates
    By Meat1000 in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 27th Nov 2008, 03:04 am
  4. Moving Object/block To Z/0 Coordinates
    By koshur in forum AutoCAD General
    Replies: 1
    Last Post: 17th Nov 2008, 06:39 pm
  5. Inserting a 3d object problem
    By timey in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 12th Nov 2005, 08:03 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts