PDA

View Full Version : Dynamic Command



randyhatchett76161
2004-11-17, 03:27 PM
Is there a way in AutoCAD to program the use of dynamic commands? Specifically, can you programmatically (VB) create a generic command with a delimiter that allows various inputs that create output based on the delimiter?

Example: There are multiple blocks in the drawing with specific attributes. A method is needed to enter a single command to zoom to a specific block with the exact attribute.

Given: The same block is inserted into the drawing fifty times. The specific attribute is a three character sequenced numeric field which falls in the range of 001-050.

The Command in the form of FBxxx, where the xxx is the three character attribute, has been programmed into a VB routine. At the command line the user enters “FB010” and AutoCAD zooms to the block with the 010 attribute.

Can this be done?

Mike.Perry
2004-11-17, 04:26 PM
Hi

Please note I've *moved* this thread from the AutoCAD General (http://forums.augi.com/forumdisplay.php?f=120) Forum to this one as I believe it would be better served here.

Thanks, Mike

Forum Moderator

randyhatchett76161
2004-11-17, 08:41 PM
Thanks, I felt that is where I should have posted it just after I hit the submit key.

Coolmo
2004-11-18, 01:45 PM
I'm very interested in a way to do that also. I know of a way to do it but it would be a VERY sloppy way so I'll hold off until a logical reply pops up here.

jwanstaett
2004-11-18, 07:21 PM
if you use you were to use FB XXX in place of FBXXX you can do it with a AutoLISP program.



;;This comand will only print the vaule of xxx
(defun c:FB ()
(setq XXX (getstring))
;;Note XXX is how set the the vaule of XXX
;;call you zoomfuction and pase it the vaule of xxx
) ;_ end of defun

Ed Jobe
2004-11-18, 08:00 PM
Here is the logic:
Prompt the user for a number.
Concatenate "FB" in front.
Search the dwg for block insertions.
For each block, check it for atts.
If it has atts, does one of them equal the input?
If it does, zoom center to the insertion point of the block.

Note: if there are more than one block that fit this criteria, you will only zoom to the first one found.

msretenovic
2004-11-19, 12:43 AM
rhatchett,

Take a look at this and let me know if it does what you want. Make sure to copy these to one of your AutoCAD support directories. Then call FB to make all of your other commands (FB001 - FB050). You will need to change the name of the block to look for. Also, make sure to change the name of the attribute to look for. I have them highlighted to make it easier for you to find.

Have a good one! :beer:

MKSxDynamicZoom.lsp


(defun c:FB(
/
cmdString
cmdNum
idx
numString
vbaPath
)
(vl-load-com)
(setq vbaPath "MKSxDynamicZoom.dvb"
idx 1
)
(while (< idx 51)
(progn
(setq cmdString "FB"
numString (itoa idx)
)
(while (< (strlen numString) 3)
(setq numString (strcat "0" numString))
)
(setq cmdString (strcat cmdString numString)
idx (1+ idx)
)
(eval (read (strcat "(defun c:" cmdString "()(setvar \"USERS5\" \"" numString "\")(vl-vbaload (findfile \"" vbaPath"\"))(vl-vbarun \"MKSxDynamicZoom\")(princ))")))
)
)
(princ)
)


MKSxDynamicZoom.dvb


Option Explicit

Public Sub MKSxDynamicZoom()
Dim zoomBlock As String
zoomBlock = ThisDrawing.GetVariable("USERS5")

Dim minPoint As Variant
Dim maxPoint As Variant

Dim atts As Variant
Dim att As Variant
Dim obj As AcadObject
Dim blk As AcadBlockReference
Dim space As AcadLayout

Set space = ThisDrawing.ActiveLayout

For Each obj In space.Block
If (obj.ObjectName = "AcDbBlockReference") Then
Set blk = obj
If ((blk.Name = "MKS") and (blk.HasAttributes)) Then ' <--Change MKS to the name of your block
atts = blk.GetAttributes
For Each att In atts
If (att.TagString = "MKS") Then '<--Change MKS to the name of your attribute
If (att.TextString = zoomBlock) Then
blk.GetBoundingBox minPoint, maxPoint
ZoomWindow minPoint, maxPoint
Exit Sub
End If
End If
Next
End If
End If
Next
End Sub

randyhatchett76161
2005-02-17, 04:24 PM
I tried this and never had any luck. I turned it over to our resident programmer and he hasn't had a chance to work on. If we get something working I'll be glad to share it.

Ed Jobe
2005-02-17, 04:46 PM
What kind of problems did you have?

arshiel88
2005-02-17, 07:44 PM
I think a better way to do it is to have a block search just like the standard "find/replace" command in autocad. first a form will show, where you have to select the block in a drop down list. after you selected the block, its attribute will be listed. Then you have to type in the value and the program will search all blocks with this attribute. Finally the "Zoom To" button, will cycle thru the found blocks. Right now I dont have the time to do this but hopefully I can submit the code soon.

randyhatchett76161
2005-02-17, 08:01 PM
I already have a routine to do that. A form is displayed that lists the Blocks by the particular attribute that I'm trying to zoom to and it also lists select other descriptive block attributes that help identify the block I'm searching for. When the attribute is found in the list I simply double-click it and the routine zooms to the block.
I was hoping to find a way to do this from the command line by typing in a couple characters that would invoke the search and zoom-to. Since I already know which block attribute that I want to zoom to I felt this way would provide a much faster way to zoom to the block. Thus I would not have to scroll down through a long list of attributes in the form to find the one I need.
By the way, is there a "good" way to sort the list of attributes displayed in a form alpha-numerically? The routine I currently use doesn't do that well when you rearrange and copy/delete the blocks.

Ed Jobe
2005-02-17, 08:48 PM
See my earlier suggestion. Type a command. (Search this forum for creating a lisp command wrapper.) The vba sub that gets run, prompts the user for the number in the attribute. That number is used to sort out the block. You can even use your form, preselecting values based upon what the user entered.

Sorting, search this forum for sorting algorithms. I believe I posted a function called BubbleSort.

rkerbo
2005-03-10, 09:30 PM
Personally I would probably make it a two step command like Ed is talking about. Type in the command name and then prompt for the block name.

But I was also thinking that it might be possible using a lisp reactor (don’t think there is a VB reactor that can do this). Look up “vlr-command-reactor” and see the event “vlr-unknownCommand”. Basically what I am thinking is the user types in “FB010”, AutoCAD responds with “unknown command”. The unknown command reactor fires, evaluates the unknown command and initiates the rest of the routine. Might be a fun challenge for someone who has the time.

Robert