Jump to content

Recommended Posts

Posted (edited)

Good morning,

Let's say i have a lisp that will erase all points in a drawing. This is a general question, maybe there is a general solution, i don't know... My lisp works ok, but in my drawing i have some blocks - and these blocks have points inside. How can i use a lisp inside of each block in a drawing? I mean, is it possible to have a lisp that will run another lisp (already made) inside of each block in a drawing?

Edited by manase
  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • MSasu

    8

  • manase

    7

  • irneb

    6

  • dbroada

    1

Popular Days

Top Posters In This Topic

Posted

Welcome to the Forum, Manase.

 

Seems to me that you are referring to two different matters. (1) To run an existing AutoLISP routine from your code just do, if defined as function:

(MyALispFunction)

respectively if defined as command:

(C:MyALispCommand)

 

 

(2) To apply the editing inside blocks, you will need to parse the entities that compose that block’s definition. Seems that your routine will require some re-work.

Posted

You might try creating a command function which steps through all blocks using the tblnext function. Then check for stuff (from the data returned by tblnext) like is it an xref / unnamed (i.e. dynamic block placeholder), if not start the BEdit command run the existing (c:CommandName) use BSave/BClose and loop to the next block. This is probably going to run very slow though, perhaps MSasu's second point may make it a lot faster.

 

Could you perhaps post the code so we can see what it does? Otherwise we can't give you a definitive answer.

Posted

As i said, this is a general question, and i want a general solution - i mean, to have a lisp that will use another lisp already made, using MSasu solution,

(C:MyALispCommand)

 

 (defun c:points ( / )
   (setq p (ssget "_x"(list '(0 . "POINT"))))
   (command "erase" p "" )
   )

 

This is a basic example - i want to erase all points in a drawing, including points that are inside of blocks (and nested blocks). For me, the best solution is a lisp that will use another lisp (already made) inside of Bedit

command (with tblnext function). If will run slow, is not a problem - only few blocks and nested blocks in my drawings.

Posted

A workaround based on your proposed solution:

; Kill Points in Blocks routine (29-VIII-2012)
(defun c:KPB( / blockItem ssetPoints )
(while (setq blockItem (tblnext "BLOCK" (not blockItem)))
 (command "_BEDIT" (cdr (assoc 2 blockItem)))
 (if (setq ssetPoints (ssget "_X" '((0 . "POINT"))))
  (command "_ERASE" ssetPoints ""
           "_BCLOSE" "_S")
  (command "_BCLOSE")
 )
)
(princ)
)

Posted

Something like this then

(defun c:points ( / p)
 (if (setq p (ssget "_x"(list '(0 . "POINT"))))
   (command "erase" p "" ))
 (princ))

(defun c:points2 (/ blk)
 (while (setq blk (tblnext "BLOCK" (not blk)))
   (if (= (logand (cdr (assoc 70 blk)) (+ 1 4 8 16 32 64)) 0) ;Check for not unnamed / xref
     (progn (command "._BEDIT" (cdr (assoc 2 blk)))
       (c:points) ;Call other lisp routine
       (command "._BSAVE" "._BCLOSE"))))
 (princ))

Posted

In this case, your solution is ok, but is not a general solution. I want to use my lisp "points" defined above, not to make a new selection of points...etc... - you don't use a lisp defined already. - this answer is for MSasu

Posted

To use the said POINTS user defined command will need to adjust it a little to return if there were points removed or not - since this will affect the way BCLOSE built-in command works.

Posted
In this case, your solution is ok, but is not a general solution. I want to use my lisp "points" defined above, not to make a new selection of points...etc... - you don't use a lisp defined already. - this answer is for MSasu
Note that this is rather specific - not actually a "generalized" thing. In this case you're fortunate since the points command can operate inside the BEdit environment and doesn't ask for any user input - else the code in my previous post wouldn't have worked fully.

 

To use the said POINTS user defined command will need to adjust it a little to return if there were points removed or not - since this will affect the way BCLOSE built-in command works.
That's why I'm using the BSave before the BClose. That way BClose works the same no matter if something's changed or not.
Posted

Please try this then:

(defun c:points( / [color=red]p[/color] )
[color=red](if[/color] (setq p (ssget "_x" (list '(0 . "POINT"))))
 (command "erase" p "")
[color=red]  T
)
[/color])
; Kill Points in Blocks routine (29-VIII-2012)
(defun c:KPB( / blockItem )
(while (setq blockItem (tblnext "BLOCK" (not blockItem[color=darkorange])))[/color]
 (command "_BEDIT" (cdr (assoc 2 blockItem)))
 (if (C:POINTS)
  (command "_BCLOSE")
  (command "_BCLOSE" "_S")
 )
)
(princ)
)

Posted

@irneb: Oops, I didn’t noticed that you already provided a (better) solution based on OP’s routine. Sorry.

 

That's why I'm using the BSave before the BClose. That way BClose works the same no matter if something's changed or not.

That a very good observation. Thank you.

Posted
@irneb: Oops, I didn’t noticed that you already provided a (better) solution based on OP’s routine. Sorry.

That a very good observation. Thank you.

No worries! I make that time of mistake all the time myself ... usually because I've not got enough time to read everything in a thread fully before posting, but sometimes just because I'm so imperfect it hurts :shock:. Thanks for the compliment! :notworthy:
Posted

An off-topic comment: Please, can a Moderator edit the title of this thread in order to remove the dots from it? It will cause accessing issues for second page and next ones on Internet Explorer. Thank you.

Posted

For this lisp, Z0.lsp - that flatten all(or almost all) objects in a drawing, can you make it work inside blocks also? I cannot do it. Thanks!

z0.lsp

Posted

Have you tried it? Tip use my code from post #6 (the c:points2 function). Rename it to something else and replace this line:

(c:points)

with this:

(c:z0)

 

Sorry, I've not tested it. If you do as above and you get errors, come back to ask about fixing them.

Posted

I've tried this way:

 

(defun c:z00 (/ blk)
 (while (setq blk (tblnext "BLOCK" (not blk)))
   (if (= (logand (cdr (assoc 70 blk)) (+ 1 4 8 16 32 64)) 0) ;Check for not unnamed / xref
     (progn (command "._BEDIT" (cdr (assoc 2 blk)))
       (c:z0) 
       (command "._BSAVE" "._BCLOSE"))))
 (princ))

 

and above i inserted z0.lsp - not working

Posted
I've tried this way:

 

(defun c:z00 (/ blk)
(while (setq blk (tblnext "BLOCK" (not blk)))
(if (= (logand (cdr (assoc 70 blk)) (+ 1 4 8 16 32 64)) 0) ;Check for not unnamed / xref
(progn (command "._BEDIT" (cdr (assoc 2 blk)))
(c:z0) 
(command "._BSAVE" "._BCLOSE"))))
(princ))

 

and above i inserted z0.lsp - not working

 

maybe try

(defun c:z0 (/ blk)

?

Posted

I'm afraid that that will not help, @dbroada. It is not a matter of recursion – the OP want to run the Z0 command (attached above as file) into a new command named Z00 for convenience. The error may be, as already stated by @irneb, from an incompatibility that prevents said code to be run while in BEDIT command. The code is quite laborious, so will be difficult to debug without the trouble-maker block.

Did you tried to call on prompter the Z0 command while in BEDIT mode?

Posted

Yes, if i use z0 command while Bedit, is ok...

Posted

What I suspect is that it encounter issues in one particular block, while working OK in others.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...