run lisp, script or Macros to select objects without interactiving with AutoCAD

run lisp, script or Macros to select objects without interactiving with AutoCAD

michaelZCXYL
Enthusiast Enthusiast
2,190 Views
35 Replies
Message 1 of 36

run lisp, script or Macros to select objects without interactiving with AutoCAD

michaelZCXYL
Enthusiast
Enthusiast

Hello,

 

I am wondering if anyone can answer the below question,

How to avoid to interactive with AutoCAD to run lisp, script or Macros to select objects, for example, revision clouds, circle, block, thank you very much in advance.

0 Likes
Accepted solutions (2)
2,191 Views
35 Replies
Replies (35)
Message 2 of 36

pendean
Community Legend
Community Legend
can you elaborate on your need, be way more specific, less generic: give an example or ten.
0 Likes
Message 3 of 36

michaelZCXYL
Enthusiast
Enthusiast
Hello Pendean,
Thank you very much for your quick response. I want to write a script to delete all revision clouds or one block for several dwgs, the problem is that I can't use the script to select objects, thanks again.
Kind regards,


[signature_844596839]
Michael Ru, CAD Operator
T (236) 521-6900 M (236) 818-8785 | michael@omengineering.ca
Suite 401 - 533 Smithe Street, Vancouver, BC V6B 6H1
O'M Engineering Electrical & Electronic Consulting Engineers | www.omengineering.ca<>



0 Likes
Message 4 of 36

ronjonp
Mentor
Mentor
Accepted solution

Here is code to delete revclouds and blocks that match a certain name.

 

(defun c:foo (/ nl s)
  ;; Change to your layer name
  (setq nl "NEWLAYERNAMEFORREVCLOUDS")
  (if (setq s (ssget "_X" '((0 . "LWPOLYLINE") (-3 ("RevcloudProps")))))
    (progn (foreach e (mapcar 'cadr (ssnamex s))
	     (entmod (append (entget e) (list (cons 8 nl))))
	     ;; (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e)))
	   )
	   ;; Make layer not plottable
	   (vla-put-plottable (vlax-ename->vla-object (tblobjname "layer" nl)) 0)
    )
  )
  ;; Need more code if this block is dynamic and modified
  (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "NAMEOFYOURBLOCK"))))
    (foreach e (mapcar 'cadr (ssnamex s))
      (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e)))
    )
  )
  (princ)
)

 

Message 5 of 36

michaelZCXYL
Enthusiast
Enthusiast

Hello Ronjonp,

 

Thank you very much for your quick response. Could you please advise me more detail on how to use it? Do the revision clouds have a name? Can this app delete circle or arc? Thanks again.

 

Kind regards,

0 Likes
Message 6 of 36

ronjonp
Mentor
Mentor

@michaelZCXYL wrote:

Hello Ronjonp,

 

Thank you very much for your quick response. Could you please advise me more detail on how to use it? Do the revision clouds have a name? Can this app delete circle or arc? Thanks again.

 

Kind regards,


The code above does not delete circles or arcs, that was not in the initial request. You need to come up with a set of rules to follow and we can delete all kinds of things. 😂 Post a sample drawing perhaps?

 

As far as how to use the code load it then call using 'FOO'.

0 Likes
Message 7 of 36

michaelZCXYL
Enthusiast
Enthusiast

Hello Ronjonp,

 

It did not work, nothing happened, please see the image below, many thanks.

 

michaelZCXYL_0-1651161808651.png

 

0 Likes
Message 8 of 36

ronjonp
Mentor
Mentor

@michaelZCXYL 

Check your drawing ... the code does not report anything. You also have to modify this to match the name of your block you want to delete.

(2 . "NAMEOFYOURBLOCK")

 

Post a sample drawing too.

0 Likes
Message 9 of 36

pendean
Community Legend
Community Legend

@michaelZCXYL wrote:

Hello Ronjonp,

It did not work, nothing happened, please see the image below, many thanks.


Did your drawing contain revclouds that are LWPOLYINE objects types?

Did you edit the LISP to include the block name you wish to delete?

 

pendean_0-1651162356264.png

 

0 Likes
Message 10 of 36

michaelZCXYL
Enthusiast
Enthusiast

I want to delete revision clouds, it has no name, thanks.

0 Likes
Message 11 of 36

michaelZCXYL
Enthusiast
Enthusiast

Yes, it can delete current drawing revision clouds. Could you please advise me how to delete revision clouds on many drawings? thanks a lot.

0 Likes
Message 12 of 36

ronjonp
Mentor
Mentor

Make sure the lisp is loaded on startup then use THIS tool calling FOO.

0 Likes
Message 13 of 36

michaelZCXYL
Enthusiast
Enthusiast

"This tool" ScriptPro 2.0 can only work on Script file. One more question, in fact, it is my initiate request. Is it possible to move revision clouds to other layer for many drawings? Sorry I did not say it clearly in the beginning.

0 Likes
Message 14 of 36

pendean
Community Legend
Community Legend
@michaelZCXYL Pay attention, a couple of obvious (and perhaps new) things for you:

1) FOO.LSP is a file that needs to be placed in a Search path of your AutoCAD session (OPTIONS command, FILES tab).
2) The folder needs to be added to the TRUSTED list in OPTIONS' FILE tab.
You create a SCRIP file, also in your AutoCAD session's Search path, that calls FOO.
You use SCRIPTPRO to run that script, which calls FOO, which runs in each file.

What else do you need to know now that I presume you edited the LISP to name the block(s) you wish to treat too.

TIA
0 Likes
Message 15 of 36

michaelZCXYL
Enthusiast
Enthusiast

SCRIPTPRO to run script only , FOO is lisp file, could you please advise me how to run it? thanks.

0 Likes
Message 16 of 36

ronjonp
Mentor
Mentor

@michaelZCXYL wrote:

"This tool" ScriptPro 2.0 can only work on Script file. One more question, in fact, it is my initiate request. Is it possible to move revision clouds to other layer for many drawings? Sorry I did not say it clearly in the beginning.


I updated the code here to move revclouds to a layer of your choosing.

 

A script file runs a series of commands on multiple drawings. In this case put the code I gave you in your startup suite and call FOO ( or name it to whatever you want ).

0 Likes
Message 17 of 36

pendean
Community Legend
Community Legend
@michaelZCXYL all a script file does it mimic what you do at the commandline.
So...
1) at the commandline you type FOO then hit <enter> to run the solution created for your by @ronjomp
2) Your script file then would repeat what you typed at the commandline.


Which did you not understand, #1 or #2 please?
Do you know how a SCRIPT file is created / written? or are we assuming too much right now?

Explain your confusion and inabilities in more detail please.
0 Likes
Message 18 of 36

michaelZCXYL
Enthusiast
Enthusiast

Huge thanks both of you! I removed revision clouds to new layer on the current drawing. When I work on multiple drawings, there are two methods for me.

1, using ScriptPro 2.0 for script app.

2. Lisp App has feature to input multiple drawings.  Please see attached one of this lisp app. When you call "Bfind", interface will pop up, thanks again.

0 Likes
Message 19 of 36

michaelZCXYL
Enthusiast
Enthusiast

So far, it is good enough. If  the following parts can be added to the App, that would be amazing.

create new layer "clouds", move clouds to clouds layer, freeze clouds layer, thanks a lot. I apologize I did not say it clearly in the beginning, thanks a lot!

0 Likes
Message 20 of 36

Sea-Haven
Mentor
Mentor

Yes can be added, but take a step back and think about what you want past this new request, its frustrating just getting please add this multiple times. Ronjonp is helping you I am sure he would prefer the full request list.

0 Likes