Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple Block rename in sequence

29 REPLIES 29
SOLVED
Reply
Message 1 of 30
Anonymous
6969 Views, 29 Replies

Multiple Block rename in sequence

Any one know how to write a LISP that enable me to direct automatic rename multiple block name?

 

Example is i have 3 block names as " A123 " , " A728 " , " A003 "

When i activate the LISP, it will automatic help me rename the block name to be " CAD1" , "CAD2" & "CAD3", whereby

the word "CAD" i can change whenever i start to use it change multipld block name.

29 REPLIES 29
Message 21 of 30
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:

 

I need to find better resources about VL stuff, and dig into it more.  I have saved two very long lists of (vl...) functions that I've run across, hoping to get a better handle on the possibilities, but neither of them includes either (vla-get-isxref) or (vla-get-islayout), though they do both include various other (vla-get-is...) functions.  Where do you find these things, or learn how to build them, if that's how it works?


 

If you have access to AutoCAD 2010 or earlier there is the acadauto.chm help file which is a reference for the ActiveX properties and methods derived from the AutoCAD Object Model. In AutoCAD 2010 or earlier, this reference can be accessed from the Visual LISP IDE Help. The reference is written for VBA, but the conversion is simple since the argument data-types and their order are identical for Visual LISP.

 

Unfortunately, since dropping VBA, Autodesk also removed the acadauto.chm file from AutoCAD 2011 onwards, and the online help doesn't include a reference for the ActiveX properties and methods.

 

As for how to work with the VLA-Objects, you can use the ActiveX reference to look up the properties and methods pertaining to every available Object, and the parameters that such properties & methods require.

 

Another way to query the properties & methods available to a VLA-Object is to use the Visual LISP vlax-dump-object function. For example, to query graphical objects, you could use a function such as:

 

(defun c:dump ( / entity )
    (if (setq entity (car (entsel)))
        (progn
            (vlax-dump-object (vlax-ename->vla-object entity) t)
            (textscr)
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

The vlax-dump-object function may also be used to query the properties & methods of non-graphical objects, such as Layouts for example:

 

(vlax-dump-object
    (vla-item
        (vla-get-layouts
            (vla-get-activedocument (vlax-get-acad-object))
        )
        0
    )
    t
)

 

The Apropos utility available in the Visual LISP IDE is also quite useful for listing the available functions if you only know part of a function. For example, type "vla-get-" then press Ctrl+Shift+Space.

 

The acadauto.chm help file is your best reference however, since, although the vlax-dump-object function lists the properties & methods and the number of parameters, it doesn't list the data-types, order of parameters or even what those parameters are. I should imagine a list of functions would be a pain to use, since there are almost 2,000 vla-* functions if I recall, and that's not including the vlax-*, vl-* and vlr-* reactor functions...

 

I hope this helps,

 

Lee

Message 22 of 30
Lee_Mac
in reply to: Lee_Mac

Did this help at all Kent?

Message 23 of 30
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:

Did this help at all Kent?


Some of it will be useful, I'm sure, when I get a chance to dig into it.  Some I already knew -- I have "dumped" objects for a long time to find out their listed VLA Properties, so as to know what I can change about them, and what their values are like.  But that doesn't give you any clue to the fact that [for instance] you can use something like (vla-get-isxref) on an Insert object to find whether it's an Xref.  That's certainly more concise than using (wcmatch) on its ObjectName property, or checking whether 4 is one of the bits making up the (assoc 70) value in its entity data.  It's those kinds of possibilities that I haven't got a handle on, but I did just find another list of (vl.... functions that includes that one [unlike other such lists I've found], so maybe that will be a source for learning what kinds of things can be checked.  Thanks for the input.

Kent Cooper, AIA
Message 24 of 30
Lee_Mac
in reply to: Kent1Cooper

Glad it helps. As I say, the key to learning really is the acadauto.chm help file, since this is a complete reference for every property and method available under the AutoCAD Object Model, including a diagrammatic hierarchy of the Object Model itself.

 

PS. Just to clarify, the 'isXref' property belongs to the block definition object, not reference. Smiley Wink

Message 25 of 30
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:
but I did just find another list of (vl.... functions that includes that one [unlike other such lists I've found], so maybe that will be a source for learning what kinds of things can be checked.

 

If you just wanted a list of all available functions, just run something like this:

 

(defun c:FunctionList ( / a b c d ) (vl-load-com)
    (if (setq b (open (setq a (vl-filename-mktemp nil (getvar 'DWGPREFIX) ".txt")) "w"))
        (progn
            (foreach c
                (acad_strlsort
                    (vl-remove-if-not
                        (function
                            (lambda ( d )
                                (member (type (eval (read d))) '(SUBR EXRXSUBR))
                            )
                        )
                        (atoms-family 1)
                    )
                )
                (write-line c b)
            )
            (close b) (startapp "notepad" a)
        )
    )
    (princ)
)

 

Message 26 of 30
ngeamtp
in reply to: pbejse

Hi pbejse,

Is that possible to modify the Lisp so that it can rename all the block in the drawing to the sequence?

 

Example, all block become CAD 1 , CAD 2 , ..........................

 

Thanks.

Message 27 of 30
pbejse
in reply to: ngeamtp


@ngeamtp wrote:

Hi pbejse,

Is that possible to modify the Lisp so that it can rename all the block in the drawing to the sequence?

 

Example, all block become CAD 1 , CAD 2 , ..........................

 

Thanks.



Why of course we can.. but tell me how you want  to number your blocks, you said "all"

Block "A" would be renamed to "CAD 1"

or

If there are 3 instances of block "A". (1) CAD 1 (2) CAD 2 (3) CAD 3 ?

What will be the basis for the sequence? Via selection? by Block name? by Location?

 

Details ngeamtp, details......

 

 

 

 

Message 28 of 30
dbranton
in reply to: Anonymous

This works really well, saved me a LOT of time.
Message 29 of 30
Anonymous
in reply to: pbejse

CAD1, CAD2, CAD3, CAD4.....
Please..!

Message 30 of 30
tomkor2066
in reply to: pbejse

@pbejse, this code works really well for me, thank you.

 

Could someone simplify the code to make it work for all blocks, no matter what the name is? The point is, I can't use wilcards "* ,?" (please don't ask why).
RenameOrder would only have a parameter: (RENAMEORDER "CAD").  I can't figure it out by myself.

 

Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost