+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 22
  1. #1
    Full Member
    Computer Details
    frostrap's Computer Details
    Operating System:
    Windows Vista
    Using
    AutoCAD 2009
    Join Date
    Dec 2007
    Location
    Tacoma, Wa, USA
    Posts
    80

    Exclamation Inserting Blocks with VBA...

    Registered forum members do not see this ad.

    I've been looking but haven't found a solution to this one yet.

    This may be hard to explain, so I'm going to throw some code out there, and hopefully someone can help me out.

    Please ask questions and I'll clarify as needed.

    Essentially this code initiates the insertion of a block, but only predetermines the scale, leaving the insertion point and rotation up to the user to determine.

    I need the user to be able to visually rotate the block on screen before completing the insertion.

    Is there any way of accomplishing what the following code does, in vba without using the .sendcommand method (perhaps with an insertblock method)?

    Code:
    ThisDrawing.SendCommand "-insert" & vbCr & thePath & vbCr & "S" & vbCr & theScale & vbCr
    I can send the rest of the Sub if you would like to see it.

    There are several reasons why I need to do this, I'll explain more as people ask... that way I wont have to write a larger book than I already have!

    Thanks for everything

    Joe
    Last edited by frostrap; 20th May 2008 at 02:01 am.

  2. #2
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    I think you cannot to do it without SendCommand (I can be wrong). Try something like this to complete your expression and continue of program execution:

    Code:
    ThisDrawing.SendCommand "(command " & Chr(34) & "._-insert" & Chr(34) & vbCr & Chr(34) & thePath & _
                              Chr(34) & " pause" & vbCr & Chr(34) & "1" & Chr(34) & vbCr & Chr(34) & theScale & Chr(34) & _
                              vbCr & Chr(34) & " pause" & Chr(34) & ")" & vbCr

  3. #3
    Junior Member
    Using
    Inventor 2011
    Join Date
    Oct 2006
    Posts
    19

    Default

    how about something like this:

    Code:
    Dim oBlock As AcadBlockReference
    Dim Pt1 As Variant
    Dim iAngle As Double
     
    Pt1 = ThisDrawing.Utility.GetPoint(, "Select Basepoint: ")
    iAngle = ThisDrawing.Utility.GetAngle(Pt1, "Select Rotation Angle: ")
    Set oBlock = ThisDrawing.ModelSpace.InsertBlock(Pt1, thePath, 1#, 1#, 1#, iAngle)
    ska

  4. #4
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    > ska67can

    Read first post

    I need the user to be able to visually rotate the block on screen before completing the insertion.

  5. #5
    Super Member
    Using
    Architecture 2009
    Join Date
    Apr 2008
    Location
    London, (sunny UK)
    Posts
    686

    Default

    You could fudge it.
    Insert the block first, then use move to set the insertion point, and rotate with reference to set the angle...
    Then confirm it and it will keep the block, else delete it...
    Like I said, fudging it...

  6. #6
    Full Member
    Computer Details
    frostrap's Computer Details
    Operating System:
    Windows Vista
    Using
    AutoCAD 2009
    Join Date
    Dec 2007
    Location
    Tacoma, Wa, USA
    Posts
    80

    Default

    I think I'm going to end up fudging it as LCE suggests.

    ska, how does "._-insert" differ from "-insert"?

  7. #7
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    The “.” preceding a command will force Autocad to use its own core command. This feature is there because it is possible to redefine a command of a given name.

    As a matter of fact it may be just what’s required if the situation described here:

    http://www.cadtutor.net/forum/showthread.php?t=23403

    is the problem at hand. Normally, employing that “SendCommand” configuration does not modify the FILEDIA variable; is it possible that the INSERT command has been redefined on your setup?

  8. #8
    Full Member
    Computer Details
    frostrap's Computer Details
    Operating System:
    Windows Vista
    Using
    AutoCAD 2009
    Join Date
    Dec 2007
    Location
    Tacoma, Wa, USA
    Posts
    80

    Default

    I've looked through the lisp files that could contain a redefinition of insert and also have looked at the command alias's, but didn't find anything.

    Actually, the reason I'm searching for alternatives to the insert command are not directly related to the mysterious filedia problem from the other post.

    There are two reasons that I was looking to not use sendcommand.

    One: I need the blocks being inserted to be inserted on a layer other than the current default layer. To accomplish this, I was temporarily changing the default layer to the insertion layer, inserting the block, then changing the default layer back to the original layer. Unfortunately, this isn't always working. If, after the insert command is issued, but before the block is inserted, the user tries to pan, AutoCAD resets the default layer to the original layer, away from the layer that I want the block to go on. To resolve this I will just change the block's layer after it's been inserted, rather than initially changing the layer that the block is being put on.

    Two: This VBA program is initiated by a small lisp routine. This allows the user to initialize the macro via the command line command "TTY". Once the user is done inserting the block they want, the VBA program closes. When the user hits enter (if TTY was the last command typed) AutoCAD should run the TTY command, and launch the block manager. Unfortunately, if I have issued a command (such as "._-insert") in the VBA code, AutoCAD will recognize that command as the last command instead of "TTY", so the user, expecting to relaunch the block manager, unintentionally launches the insert command.

    I have a workaround for this in my mind, but haven't tested it yet, and was hoping to get some more suggestions from the folks on here.

    That was a mouthful! Any other ideas?

  9. #9
    Super Member
    Using
    Architecture 2009
    Join Date
    Apr 2008
    Location
    London, (sunny UK)
    Posts
    686

    Default

    I would strongly advise that you look into the use of VB.NET, rather than VBA as it will help with a lot of what you have explained above. No need to run it from a lisp as the command is defined in the vb.net app. and you can call commands without sending them to the command line. So the last command would be your defined command, rather than any that you call from your app.

  10. #10
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    Registered forum members do not see this ad.

    Using .NET is good advice – unfortunately 2004 predates that API.

    Is “dynamic feedback” actually that important? Sure, it would be nice but withholding that bit of eye candy to avoid SENDCOMMAND seems worth it.

    Something like this may give sufficient reference:


    Code:
    Sub InsertWithReference()
    Dim varInsertPt As Variant
    Dim varInsertPtTran As Variant
    Dim entInsert As AcadBlockReference
    Dim dblOr(2) As Double
    Dim dblX(2) As Double
    Dim dblZ(2) As Double
    Dim varZ As Variant
    Dim varX As Variant
    Dim dblAngle As Double
    Dim entRay As AcadRay
       dblX(0) = 1#
       dblZ(2) = 1#
       With ThisDrawing
          varZ = .Utility.TranslateCoordinates(dblZ, acUCS, acWorld, 1)
          varInsertPt = .Utility.GetPoint(, "Insertion Point: ")
          varInsertPtTran = .Utility.TranslateCoordinates(varInsertPt, acWorld, acUCS, 0)
          varX = .Utility.TranslateCoordinates(dblX, acOCS, acUCS, 1, varZ)
          dblAngle = .Utility.AngleFromXAxis(dblOr, varX)
          varX(0) = varInsertPtTran(0) + 1
          varX(1) = varInsertPtTran(1)
          varX(2) = varInsertPtTran(2)
          Set entInsert = .ModelSpace.InsertBlock(varInsertPt, "A", 1#, 1#, 1#, -dblAngle)'adjust block name as needed
          Set entRay = .ModelSpace.AddRay(varInsertPt, .Utility.TranslateCoordinates(varX, acUCS, acWorld, 0))
          entRay.Highlight True
          varX = .Utility.GetPoint(varInsertPtTran, "Adjust angle: ")
          varInsertPtTran = .Utility.TranslateCoordinates(varInsertPt, acWorld, acOCS, 0, varZ)
          varX = .Utility.TranslateCoordinates(varX, acWorld, acOCS, 0, varZ)
          dblAngle = .Utility.AngleFromXAxis(varInsertPtTran, varX)
          entInsert.Rotation = dblAngle
          entRay.Delete
       End With
    End Sub

Similar Threads

  1. Inserting Blocks
    By Michael Henson in forum AutoCAD Drawing Management & Output
    Replies: 6
    Last Post: 6th Feb 2008, 04:00 pm
  2. Inserting blocks
    By edortizr6 in forum AutoCAD Beginners' Area
    Replies: 21
    Last Post: 7th Nov 2007, 06:30 pm
  3. Inserting Blocks
    By happyunited in forum AutoCAD Drawing Management & Output
    Replies: 11
    Last Post: 23rd Jul 2007, 04:27 pm
  4. Inserting blocks
    By johnengineer in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 25th Apr 2007, 05:01 pm
  5. Inserting blocks
    By misha in forum AutoCAD General
    Replies: 1
    Last Post: 1st Jun 2006, 02:33 am

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