• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1599
  • Last Modified:

Looking for ideas on VBA projects

Ive been programming with VBA extensively for the last couple of years (mostly in office).  Until recently, Ive only done a few AutoCAD programs, mostly because of a lack of ideas.  I could always think of hundreds of things that need to be automated in database applications, but came up with a blank when it comes to autocad automation.  Im looking for some other autocad gurus to weigh in on this topic and tell what kinds of programs theyve written to automate or enhance productivity.  Hopefully this thread can spark some lively discussion and lead to other threads and some code exchange.

Regards,

Bill
0
BillPowell
Asked:
BillPowell
  • 12
  • 10
  • 5
  • +1
3 Solutions
 
norrin_raddCommented:
hey bill,
interesting topic.
They latest thing that I have been working on is keeping a log of my dwgs in a database and updating that data through acad with vba.
I keep up with the basics like filepath, asbuilt/proposed, date, dwgname, number, layoutname, sheet # of #, description, job number, etc..
I even use it to open dwgs, so when somebody comes in and says "i need a 11x17 of that anderson project" I open my userform and look for it by name, or if they come in and ask for job number I can look that way too, just double click it in the userform and it opens up.
Its still a work in progress but it has come in handy already, and works pretty good so far. a lot easier than keeping it in excel or hard copy. And I can use the data in access too for reports and such.

I've got a lot of little macros that I use daily.

I recommend that you look at the vba samples that came with your acad if you havent already, I use some of those on a regular basis like the block replacer.
0
 
MuertyCommented:
A simple VBA program I implemented was a plotting routine. In our office we have 4 different plotter sets that we produce, depending upon the project, client and plotter. All of our projects have the same layouts so it made sense to automate the plotting of the several drawings we have for each client. It produces each plot in sequential order to the plotter of choice, and the number of copies needed.
0
 
BillPowellAuthor Commented:
norrin_radd

Where are you storing the data.  I thought of doing the same thing with our drawing files, but when I look at the data controls in Autocad, they seem to pale incomparison to what comes with access.  How are you updating the database, with data bound controls or ADO?  If you dont mind elaborating a bit, perhaps a couple code samples of what your doing that would be great.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
norrin_raddCommented:
bill,
I'm using DAO. I know there is a difference, but what it is I dont know. I'm storing the data in access. The code has gotten pretty complicated and seems to be growing everytime I think I need to add something.
but in all honesty and to give credit where it is due, all of my knowledge came from this set of articles:

http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=3027392&linkID=2786836

after I went through these tutorials I was able to make some changes, for instance updating my textboxes from my titleblock attribs and vice versa, customizing my sql strings and things like that. but those articles were key in getting started.

I'll tell you the hardest part has been comming up with the sql code to do what I want. I figured out that if I can get a query to work right in access I can copy paste the sql and use that in my cad application and it works with just a little bit of tweakage pertaining to certain strings.

I'll post more of my code later but the guy the did those articles(dave espinosa-aguilar) does alot better job than I can with code.
good luck
0
 
BillPowellAuthor Commented:
Thanks for the link. Ill have a good look.  One program I recently wrote involves autoindexing of drawings.  That is, whatever drawing I have open when I call the procedure, it will search a specified directory, find the drawing with the highest drawing number for that year, add one to it and save the current drawing with that name.  One thing I had not figured out was how to pass a variable to a procedure when calling that procedure from a custom button.  For example, in the program I mentioned if I make the windows directory a variable to be passed to the procedure, I can use the same procedure with several different command buttons, each passing a different value.
0
 
norrin_raddCommented:
Did you get it? Did you try using a function for that?
 hypothetically:

public function index(dir as string)

code & dir & code

end function

********

then call the function from your custom button or sub:

sub button1()
index("c:\whateverDir")
end sub


I do some stuff like that.
0
 
BillPowellAuthor Commented:
The button was on a custom toolbar, not a user form.
0
 
norrin_raddCommented:
the more I think about the more I really need to make a routine like muerty mentioned. right now I use basically scripted buttons to print, that seems so r12ish ;) I need to get away from that.
 I wonder how many people use Diesel anymore. I've been tasked with trying to customize Lt2005, which sripts and diesel is all you get pretty much, talk about dusting off cobwebs.
0
 
norrin_raddCommented:
<The button was on a custom toolbar, not a user form.>
did you get a solution?
0
 
BillPowellAuthor Commented:
Not yet, I got an error when trying to pass a parameter through a button on the toolbar, but the procedure works fine when run at the module level.
0
 
norrin_raddCommented:
try this in your button:

^C^C(setvar "USERI1" 1) -vbarun;yourprocdedure
*******
in your procdure catch the user1 variable

dim uservar as string
uservar = ThisDrawing.GetVariable("USERI1")

select case uservar

case 1
'hit your function
index("c:\whateverDir")

case 2
'and so on and so forth
***********
you can copy/paste that button string and just change the user1 variable. autodesk gave us 5 user variables to use like this. then just add to the select case as needed.

thats one way to do it using a little lisp/vba mocha blend ;)
I use this method for a toolbar that sets up to draw on with specific settings.
0
 
BillPowellAuthor Commented:
Okay, seems straight forward, but why cant sytax like this be used:
-vbarun;MyProcedure("c:\whateverDir")
0
 
norrin_raddCommented:
just cant do it, not from the command line which is what the button is doing basically, thats just the way they made it, you may look into using vbastmt command, look it up in the help files.
there is another vba/lisp method too, got this from another group not sure if it works never really tried it:

Solution
It is not possible to pass parameters directly into a VBA macro from
AutoCAD; however, you can use the GetString function in VBA and the
(command) function from AutoLISP to pass data. The following example shows
how to pass data using VBA and AutoLISP to a VBA macro.

In the MODULE :

Public Param1, Param2 As String

Sub MyMacro()
Param1 = ThisDrawing.Utility.GetString(False)
Param2 = ThisDrawing.Utility.GetString(False)

'Enter your code here
End Sub

Then call the VBA macro as:

(command "-VBARUN" " MyMacro " "Argument1" "Argument2")

Note: The project needs to be loaded before callingl the macro, otherwise
use (command "-VBALOAD" "ProjectName.dvb") to load the project.
0
 
BillPowellAuthor Commented:
Good to know theres a workaround.  Im going to keep this open a few days to see if anyone else dials in.  Anybody who posts an idea will get a cut of the points.
0
 
haikleCommented:
Bill
If you are still looking for ideas. Here's one to consider.
When dealing with a large project with design files residing on a server, there's no way to tell who has the drawing open unless you have access to the server.

Autodesk at one time (perhaps still does) published an app called WHOHAS.ARX that when loaded on every install of AutoCAD would allow everyone to use the ARX app to identify who has a file open. The trick is that WHOHAS.ARX has to be loaded on every computer running AutoCAD. The other thing about it is that you can check the status of only one file at a time.

If you could somehow capture the same info for all files in a folder and display it in a listbox (i.e. Windows Explorer style), you'd have a nice useful project interface. This is really helpful if you have lots of folks working on multiple drawings.

I know this is vague but that's because I haven't really attempted to figure out how to do it.

haikle
0
 
BillPowellAuthor Commented:
Yes thanks, Im always open to new ideas.  That is a good one as well.  Keep em comin!
0
 
BillPowellAuthor Commented:
Im even looking for good ideas on small little productivity apps like this one I wrote to sum the areas of objects in a selection set.

Public Sub AreaSum()
Dim selection As AcadSelectionSet
Dim obj As AutoCAD.AcadObject
Dim sum As Double
Dim ha As Double
Dim acres As Double
On Error Resume Next
sum = 0
Set selection = ThisDrawing.ActiveSelectionSet
'Loop through selection set and add up the entities
For Each obj In selection
  sum = sum + obj.Area
Next obj
ha = Round(0.0001 * sum, 3)
acres = Round(0.000247 * sum, 3)
sum = Round(sum, 3)
'Display the final value
MsgBox sum & " Sqare Metres" & vbCrLf & ha _
& " Hectares" & vbCrLf & acres & " Acres"
End Sub
0
 
BillPowellAuthor Commented:
The one problem I had with the above code was that the procedure uses the last active selection set if you lauch the procedure with nothing selected and I cant figure out why.  It works fine if you always have something selected when you launch it.
0
 
haikleCommented:
Bill

Take a look at this and see if it helps.
Substituting
ThisDrawing.PickfirstSelectionSet for ThisDrawing.ActiveSelectionSet

http://discussion.autodesk.com/thread.jspa?threadID=348485
0
 
haikleCommented:
------------Way off topic, but try this.-------------------

Public Sub AreaSum()
Dim selection As AcadSelectionSet
Dim obj As AutoCAD.AcadObject
Dim sum As Double
Dim ha As Double
Dim acres As Double
On Error Resume Next
sum = 0
Set selection = ThisDrawing.PickfirstSelectionSet

If selection.count = 0 Then selection.SelectOnScreen

'Loop through selection set and add up the entities
For Each obj In selection
  sum = sum + obj.Area
Next obj
ha = Round(0.0001 * sum, 3)
acres = Round(0.000247 * sum, 3)
sum = Round(sum, 3)
'Display the final value
MsgBox sum & " Sqare Metres" & vbCrLf & ha _
& " Hectares" & vbCrLf & acres & " Acres"
End Sub
0
 
norrin_raddCommented:
this is a good one if you want to delete all layer filters:

Public Sub dellayfil()

On Error Resume Next
Dim oDict As AcadDictionary
Dim LayFlt As Object
Dim oXrec As AcadXRecord
Dim liLayFltCount As Integer


Set oDict = ThisDrawing.Layers.GetExtensionDictionary
If oDict.Count > 0 Then
Set LayFlt = oDict.Item("ACAD_LAYERFILTERS")
liLayFltCount = LayFlt.Count
For Each oXrec In LayFlt
oXrec.Delete
Next
End If
Set oDict = ThisDrawing.Layers.GetExtensionDictionary
If oDict.Count > 0 Then
Set LayFlt = oDict.Item("AcLyDictionary")
liLayFltCount = LayFlt.Count
For Each oXrec In LayFlt
oXrec.Delete
Next
End If
End Sub
0
 
haikleCommented:
< Okay, seems straight forward, but why cant sytax like this be used:
-vbarun;MyProcedure("c:\whateverDir") >

The following seems to work for me.
It loads app.dvb if it's not already loaded.

"-vbarun c:\acadsupp\app.dvb!RoutineName "

or

"-vbarun c:\acadsupp\app.dvb!modulename.RoutineName "
0
 
norrin_raddCommented:
yeah but he was talking about if your routine was something like:
public sub routine(whateverdir as string)

and why you couldnt pass the whateverdir variable from the command line like:

"-vbarun c:\acadsupp\app.dvb!modulename.RoutineName("whateverdir") "

that wont work, seems stupid that it doesnt, maybe they will fix that in the next release.
0
 
BillPowellAuthor Commented:
Good discussion we've had here guys.  Thanks for the input.
0
 
BillPowellAuthor Commented:
Also with the closing of this question, we now have our first CAD Certified Expert "Master"
Congratulations norrin_radd !!
0
 
haikleCommented:
< yeah but he was talking about if your routine was something like:
public sub routine(whateverdir as string) >

Sorry about that. Misunderstood the issue.

Congratulations norrin_radd!
0
 
norrin_raddCommented:
thanks guys
0
 
BillPowellAuthor Commented:
Im posting another question right now that you guys may be able to help with.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 12
  • 10
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now