Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Run Lisp in VBA from Button_Click

  1. #1
    Member
    Join Date
    2002-10
    Location
    Phoenix AZ
    Posts
    12
    Login to Give a bone
    0

    Default Run Lisp in VBA from Button_Click

    I have tried ThisDrawing.SendCommand to run the following lisp from VBA without any luck. The lisp calls for an Insertion Point and then inserts a block with 3 attributes. I've attached the block and lisp for clarity. Does anyone know the code I would need in VBA to insert this block as if running the lisp on it's own? I am running ACAD MEP 2010 on a 64bit machine in Windows 7.

    Flex.lsp

    (DEFUN C:Flex ()
    ;
    (setvar "attdia" 0)
    (setvar "osmode" 512)
    ;

    (Prompt "\nSelect Insertion Point")
    (setq pt1 (getpoint))
    ;
    (command "-insert" "G:/detail/_UMEC-Toolbox/Blocks/PNIDBlocks/flex.dwg" pt1 "1")
    )
    Attached Files Attached Files

  2. #2
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    What "command" string are you sending with the SendCommand? Is the lisp loaded already or do you need the button click to load it first and then run the command?

  3. #3
    100 Club RobertAitken's Avatar
    Join Date
    2000-10
    Location
    Sunny Scotland
    Posts
    148
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    Why don't you just insert the block using VBA code?

    The list routine you have is basically a script to insert a block so why not write it in VBA and do everything in VBA instead of trying to get VBA to pass it to lisp.

    I could understand if the lisp routine was a function that was difficult to replicate in VBA.

    Just a thought.

    Robert

  4. #4
    Member
    Join Date
    2002-10
    Location
    Phoenix AZ
    Posts
    12
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    I originally tried inserting the block with VBA code, but could not get that to work either. I'm still a little green in the VBA world.

    When I run the two SendCommand functions together, I get an error on the load. Seperately, I can load the lisp, but not run the command. I would be happy to get it to work either by calling a lisp or with the vba code itself - it seems that would be cleaner and less files to pull from.

    To load the lisp, I'm using:
    ThisDrawing.SendCommand "(load ""G:/detail/_UMEC-Toolbox/lsp/PNID/DataFiles/Flex.lsp"") "

    I'm having a problem running the command:
    ThisDrawing.SendCommand "flex"

    I get a Run-time error '-2147418111(80010001':
    Automation error
    Call was rejected by callee.

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    Code that is executed with SendCommand is run asyncronously from vba execution. When you call 'flex', the lisp isn't loaded yet. Do a search in this forum for 'lisp' for some workarounds.
    C:> ED WORKING....


    LinkedIn

  6. #6
    100 Club RobertAitken's Avatar
    Join Date
    2000-10
    Location
    Sunny Scotland
    Posts
    148
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    Post the code you had for inserting the block and I'll have a look at it.

    Inserting blocks isn't to much hassle.

    ThisDrawing.ModelSpace.InsertBlock(dblInsPt, strBlockPathName & strBlockName & ".DWG", 1#, 1#, 1#, 0#) works

    Robert

  7. #7
    Member
    Join Date
    2002-10
    Location
    Phoenix AZ
    Posts
    12
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    Thanks Robert, here is the code...

    Private Sub FlexButton_Click()
    Dim varInsertionPoint As Variant
    Dim XYZScale As Double
    Dim dblRotation As Double
    Dim ls_filename As String

    ls_filename = "G:\detail\_UMEC-Toolbox\Blocks\PNIDBlocks\FlexTemp.dwg"

    XYZScale = 1
    dblRotation = 0

    With ThisDrawing.Utility
    .InitializeUserInput 1
    varInsertionPoint = .GetPoint(, vbCr & "Select Insertion Point: ")
    End With

    End Sub

  8. #8
    Member
    Join Date
    2002-10
    Location
    Phoenix AZ
    Posts
    12
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    I have also tried this code for inserting a block with no luck...

    Private Sub FlexButton_Click()

    Dim objBlockRef As AcadBlockReference
    Dim ip As Variant
    Dim ep As Variant

    On Error Resume Next


    ip = ThisDrawing.Utility.GetPoint(, vbCr & "Select Insertion Point: ")
    ep = ThisDrawing.Utility.GetAngle(ip, "Select block rotation angle:")

    Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(ip, "G:\detail\_UMEC-Toolbox\Blocks\PNIDBlocks\FlexTemp.dwg", 1#, 1#, 1#, ep)

    objBlockRef = Nothing

    End Sub

  9. #9
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    There's some sample code in the developer guide. Look for a link to it on the Help menu.
    C:> ED WORKING....


    LinkedIn

  10. #10
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Run Lisp in VBA from Button_Click

    Quote Originally Posted by mpair View Post
    I have also tried this code for inserting a block with no luck...

    Private Sub FlexButton_Click()

    Dim objBlockRef As AcadBlockReference
    Dim ip As Variant
    Dim ep As Variant

    On Error Resume Next


    ip = ThisDrawing.Utility.GetPoint(, vbCr & "Select Insertion Point: ")
    ep = ThisDrawing.Utility.GetAngle(ip, "Select block rotation angle:")

    Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(ip, "G:\detail\_UMEC-Toolbox\Blocks\PNIDBlocks\FlexTemp.dwg", 1#, 1#, 1#, ep)

    objBlockRef = Nothing

    End Sub
    Compare with this code

    Code:
     
    Private Sub FlexButton_Click()
    Dim objBlockRef As AcadBlockReference
    Dim ip As Variant
    Dim ep As Variant
    Dim blkName As String
     
    On Error GoTo Err_Control '<-- do not use On Error Resume Next
     
    Me.Hide '<--hide form
     
    blkName = "G:\detail\_UMEC-Toolbox\Blocks\PNIDBlocks\FlexTemp.dwg" '<-- define all variables explicitly before
     
    ip = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Insertion Point: ")
    ep = ThisDrawing.Utility.GetAngle(ip, vbCrLf & "Select block rotation angle:")
    Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(ip, blkName, 1#, 1#, 1#, ep)
    Set objBlockRef = Nothing '<-- this is object thus you can use Set to release them
    Me.Show '<-- unhide
     
    Err_Control:
    If Err.Number <> 0 Then
    MsgBox Err.Description
    End If
     
    End Sub
    hth

    ~'J'~

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 13
    Last Post: 2014-01-20, 06:14 PM
  2. NEED HELP WITH LISP ROUTINE - PURGE linetype lisp
    By ECASAOL350033 in forum AutoLISP
    Replies: 6
    Last Post: 2013-06-21, 01:13 AM
  3. Replies: 3
    Last Post: 2012-05-07, 08:16 PM
  4. Replies: 9
    Last Post: 2012-01-21, 07:58 AM

Posting Permissions

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