Author Topic: Complete newbie question: Loading VB apps?  (Read 3057 times)

0 Members and 1 Guest are viewing this topic.

C. Alan

  • Guest
Complete newbie question: Loading VB apps?
« on: October 14, 2006, 12:48:27 PM »
I am nearly a complete newbie to VBA.  I have written some code before, but it was for Virtual Pinball (a fun way to learn to code).  I have been working through some tutorials in the last few days, and I have one question that is really bugging me.

Most all of the tutorials involve running your VB Application from the VB editor.  So far, I have not been able to make the connection as to how to take my finished Application, and actually use it in autocad without having to open the VB editor.

I would like to be able to run my code from either the command line, or from a tool bar button.

Can some one point me to a good tutorial for loading, and executing your VB code in Autocad?

Thanks,
C. Alan

daron

  • Guest
Re: Complete newbie question: Loading VB apps?
« Reply #1 on: October 14, 2006, 01:34:49 PM »
C. I believe it can be done through a lisp call or as a macro in a toolbar. I'm pretty sure of this. Try typing vbarun or checking through the search with vbarun and selecting the lisp forum. I know it has been discussed before. However, weekends are usually pretty slow. You might check in over the week. I'm sure you'll get better answers than I can give.

Dinosaur

  • Guest
Re: Complete newbie question: Loading VB apps?
« Reply #2 on: October 14, 2006, 01:37:41 PM »
I had the same problem when I first started finding some VBA applications I wanted to try . . . I started looking around and found the VBALoad and VBARun commands.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
TheSwamp.org  (serving the CAD community since 2003)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Complete newbie question: Loading VB apps?
« Reply #4 on: October 14, 2006, 02:07:30 PM »
Mark's link covers most of it.
I use menus for most of my vba, as it is less noisy on the screen than a heap of toolbars.
Once you get over the rage, the Cui allows you to add to the menu fairly easily.
I also use lisp to create commands.
In notepad add 
Code: [Select]
(defun c:LayerOff()
  (command "-vbarun" "Layers.LayerOff")
  (princ))

and save it as  LayerOff.LSP

Then in your acaddoc.lsp (Make one in notepad if you haven't one)
add the line
Code: [Select]
(autoload "LayerOff"         '("LayerOff"))
Now you have access to the command line, typing layeroff will run the sub of that name in the project you have loaded.

C. Alan

  • Guest
Re: Complete newbie question: Loading VB apps?
« Reply #5 on: October 14, 2006, 03:25:19 PM »
Thanks for the Link Mark, that was exactly what I was looking for.

Bryco:  Thanks for the lisp idea.  I know what you mean about the CUI, Between that and the problems we have had with the license server software, my office dumped its anual subscription last year.

--C. Alan

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Complete newbie question: Loading VB apps?
« Reply #6 on: October 14, 2006, 03:52:25 PM »
Quote
office dumped its anual subscription last year
  Hehe get those people at Autodesk where it hurts, :pissed:
« Last Edit: October 14, 2006, 03:54:18 PM by Bryco »

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Complete newbie question: Loading VB apps?
« Reply #7 on: October 15, 2006, 12:12:18 AM »
Thanks for the Link Mark, that was exactly what I was looking for.

Very good! Welcome to theswamp ...........
TheSwamp.org  (serving the CAD community since 2003)

C. Alan

  • Guest
Re: Complete newbie question: Loading VB apps?
« Reply #8 on: October 16, 2006, 01:05:16 AM »
Well, I have had some minor sucess with my first applicaiton.  I do a lot of hydrology work, and I wanted to make a macro that I could use to click on a closed poly line and get the area back in Acres.

I have gotten my macro to work, and I have attached it to a tool button.

I am currently using LDD 2004.  This is the code for my tool bar button

C^C-vbarun Area.dvb!Module1.AreaConvert

My code more or less looks like this:
Module1
Code: [Select]
Option Explicit
Sub AreaConvert()

Form1.show

End Sub

Form1
Code: [Select]
Private Sub UserForm_Initialize()
Me.Hide

On Error Resume Next
With ThisDrawing.Utility

    .GetEntity Pick_Area, Pick_point, vbCrLf & "Select a closed polyline:"
       
        'Check for No Selection
        If Pick_Area Is Nothing Then
            .Prompt vbCr & "You did not pick anything."
            End
        End If
       
       'Check for Object type and Closed Polyline
        If Pick_Area.ObjectName = "AcDbPolyline" Then
           
            'nested if to check for closed polylines
            If Pick_Area.Closed = True Then
                Area_ft = Pick_Area.Area
                Area_Acres = Pick_Area.Area / 43559.45832
            Else
            .Prompt vbCrLf & "You did not pick a closed polyline."
            End
           
            End If
           
            Else
            .Prompt vbCrLf & "You did not pick a closed polyline."
            End
       
        End If
       
        'test routine that were used durring development
    '.Prompt vbCrLf & "Object name " & Pick_Area.ObjectName
    '.Prompt vbCrLf & "selected point " & Pick_point(0) & "," & Pick_point(1)
    '.Prompt vbCrLf & "closed " & Pick_Area.Closed

End With

sqfoot.Caption = Area_ft
acres.Caption = Area_Acres

Me.show
End Sub

The code executes more or less.  The only think I don't like is the command line echo that you see when you click on the toolbar button:

Command: -vbarun
Macro name: Area.dvb!Module1.AreaConvert
Select a closed polyline:
Command: Execution error

Is there anyway not to have these items echo to the command line?  What is the Execution error message mean?

Thanks,
C. Alan

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complete newbie question: Loading VB apps?
« Reply #9 on: October 16, 2006, 02:13:50 AM »
What happens if you prefix the menu command with
^C^C^P
ie C^C^P-vbarun Area.dvb!Module1.AreaConvert

^P toggles MENUECHO on and off

/// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.