Author Topic: LISP to access Block level outside of another block of a clicked entity?  (Read 9538 times)

0 Members and 1 Guest are viewing this topic.

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #15 on: September 04, 2016, 01:22:59 PM »
when I create a block with 5 levels of nesting, I get 5 entities listed in the last part of (nentsel), are you sure your block has the 5 levels? Your list has only 4.

Code - Auto/Visual Lisp: [Select]
  1. Select entity: (<Entity name: 8b0e7d60> (822.455460918527 138.21672852515 0.0) ((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (820.934460918528 135.44623025574 0.0)) (<Entity name: 8b22c9a0> <Entity name: 627c4930> <Entity name: 6c7525f0> <Entity name: 6c74baf0> <Entity name: 661a06c0>))

I'm not sure how to fix that code, but this works for me to edit 5th level of test block I made.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:myblockedit ( / lst )
  2.   (command "_.refedit" pause "n" "n" "n" "n" "ok" "all" "y")
  3.   (princ)
  4. )
  5.  

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #16 on: September 04, 2016, 08:41:59 PM »
when I create a block with 5 levels of nesting, I get 5 entities listed in the last part of (nentsel), are you sure your block has the 5 levels? Your list has only 4.

Code - Auto/Visual Lisp: [Select]
  1. Select entity: (<Entity name: 8b0e7d60> (822.455460918527 138.21672852515 0.0) ((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (820.934460918528 135.44623025574 0.0)) (<Entity name: 8b22c9a0> <Entity name: 627c4930> <Entity name: 6c7525f0> <Entity name: 6c74baf0> <Entity name: 661a06c0>))

I'm not sure how to fix that code, but this works for me to edit 5th level of test block I made.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:myblockedit ( / lst )
  2.   (command "_.refedit" pause "n" "n" "n" "n" "ok" "all" "y")
  3.   (princ)
  4. )
  5.  

Hi dan. Ran your LISP & when i click on the entity of the block, it went straight to the the reference edit dialog box highlighting Block 4. But What I require is when i click the entity of Block 4 it will bring me to Block 5 instead. As mention on the subject

Quote
LISP to access Block level outside of another block of a clicked entity?

Also, the nesting levels are not necessary the same.

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #17 on: September 06, 2016, 12:56:41 PM »
sorry - didn't text on upper level entity. So you want to always refedit one level up from nested entity selected?

when you refer to block 5 vs 4, what is order of nesting? my reference uses block 1 as top level / outer block, with block 5 nested the most inside the block.

taking out one "n" works for selecting 4th level. If you want to have the code flexible for any nesting, then the code would need to count number of nested blocks and repeat "n" one less than level of selected block. I don't have time to try and write that code, but I think that is what roy_043's code is trying to do.
https://www.theswamp.org/index.php?topic=51887.0#subject_569264

Code - Auto/Visual Lisp: [Select]
  1. (defun c:myblockedit ( / lst )
  2.   (command "_.refedit" pause "n" "n" "n" "ok" "all" "y")
  3.   (princ)
  4. )


ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #18 on: September 06, 2016, 06:42:47 PM »
sorry - didn't text on upper level entity. So you want to always refedit one level up from nested entity selected?

Yes
 
when you refer to block 5 vs 4, what is order of nesting? my reference uses block 1 as top level / outer block, with block 5 nested the most inside the block.

The block that I require is usually not the deepest nested level.

I use this LISP to get the nesting level & block name

Code: [Select]
(defun C:XS01 (/ EN ENT LEVEL NENT NLVL MSG)
  (setq NENT (nentsel)
        EN   (car NENT)
        ENT  (entget EN)
  )
  (setq MSG (strcat "\nEntity type >>>"
                  (cdr (assoc 0 ENT))
                  "  layer>>> "
                  (cdr (assoc 8 ENT))
          )
  )
  (setq NLVL  (1- (length (cadddr NENT)))
        LEVEL 0
  )
  (foreach EN (reverse (cadddr NENT))
    (progn (setq ENT (entget EN))
           (prompt (strcat "\n[[nesting level]] "
                           (itoa LEVEL)
                           "  [[Block Name]] "
                           (cdr (assoc 2 ENT))
                           "  [[layer]] "
                           (cdr (assoc 8 ENT))
                   )
           )
           (setq NLVL  (1- NLVL)
                 LEVEL (1+ LEVEL)
           )
    )
  )
  (prompt MSG)
  (princ)
)

Running the above LISP, clicking the lower right square, it indicates that

Block name = 5 ( since I want access to the block outside the block of the clicked entity)
Nesting Level = 2nd level

Quote
Command: xs
Select object:
[[nesting level]] 0  [[Block Name]] 8  [[layer]] 0
[[nesting level]] 1  [[Block Name]] 6  [[layer]] 0
[[nesting level]] 2  [[Block Name]] 5  [[layer]] 0
[[nesting level]] 3  [[Block Name]] 4  [[layer]] 0
Entity type >>>LWPOLYLINE  layer>>> 0
Command:

taking out one "n" works for selecting 4th level. If you want to have the code flexible for any nesting, then the code would need to count number of nested blocks and repeat "n" one less than level of selected block. I don't have time to try and write that code, but I think that is what roy_043's code is trying to do.
https://www.theswamp.org/index.php?topic=51887.0#subject_569264

Code - Auto/Visual Lisp: [Select]
  1. (defun c:myblockedit ( / lst )
  2.   (command "_.refedit" pause "n" "n" "n" "ok" "all" "y")
  3.   (princ)
  4. )

When you posted the previous code, I already tried adjusting the number of "N" in your code but it still does not preselect Block 5 in the reference editor but always Block 4 regardless of the number of "N" in the code.

roy_043's code unfortunately works on  BricsCAD but not AutoCAD.

But thanks for helping me this far.
« Last Edit: September 06, 2016, 07:45:24 PM by ctrlaltdel »

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #19 on: September 06, 2016, 08:40:59 PM »
In Brics below code works for me. I tried to get fancy with repeats on "n" commands but couldn't work it out, the dumb cond method did the trick. This may still not work for you in Acad, perhaps typing and sharing command prompt testing the number of "n" commands could help. (Side note - I thought Roy's code didn't work due to stupid error on my part test loading with some other unrelated code.)

Code - Auto/Visual Lisp: [Select]
  1. (defun C:XS01 (/ EN ENT LEVEL NENT NLVL MSG)
  2.   (setq NENT (nentsel)
  3.         EN   (car NENT)
  4.         ENT  (entget EN)
  5.   )
  6.   (setq MSG (strcat "\nEntity type >>>"
  7.                   (cdr (assoc 0 ENT))
  8.                   "  layer>>> "
  9.                   (cdr (assoc 8 ENT))
  10.           )
  11.   )
  12.   (setq NLVL  (1- (length (cadddr NENT)))
  13.         LEVEL 0
  14.   )
  15.   (foreach X (reverse (cadddr NENT))
  16.     (progn (setq ENT (entget X))
  17.            (prompt (strcat "\n[[nesting level]] "
  18.                            (itoa LEVEL)
  19.                            "  [[Block Name]] "
  20.                            (cdr (assoc 2 ENT))
  21.                            "  [[layer]] "
  22.                            (cdr (assoc 8 ENT))
  23.                    )
  24.            )
  25.            (setq NLVL  (1- NLVL)
  26.                  LEVEL (1+ LEVEL)
  27.            )
  28.     )
  29.   )
  30.   (prompt MSG)
  31.   (cond
  32.     ((= 1 LEVEL)(command "refedit" (cadr NENT) "ok" "all" "y"))
  33.     ((= 2 LEVEL)(command "refedit" (cadr NENT) "ok" "all" "y"))
  34.     ((= 3 LEVEL)(command "refedit" (cadr NENT) "n" "ok" "all" "y"))
  35.     ((= 4 LEVEL)(command "refedit" (cadr NENT) "n" "n" "ok" "all" "y"))
  36.     ((= 5 LEVEL)(command "refedit" (cadr NENT) "n" "n" "n" "ok" "all" "y"))
  37.     ((= 6 LEVEL)(command "refedit" (cadr NENT) "n" "n" "n" "n" "ok" "all" "y"))
  38.   )
  39.   (princ)
  40. )
  41.  
« Last Edit: September 06, 2016, 09:18:30 PM by dan allen »

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #20 on: September 07, 2016, 12:43:47 AM »
Hi Dan: What is your new LISP suppose to do when you run it?

When i run it, I get this: See photo

Incidentally, this is also what I get base on your previous LISP
« Last Edit: September 07, 2016, 01:09:51 AM by ctrlaltdel »

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #21 on: September 07, 2016, 11:47:10 AM »
ctrlaltdel,

the lisp runs command line of refedit and jumps into the block w/out dialog. In acad, does -refedit work at the command line? If it does, try adding the hyphen to REFEDIT in the code

Code: [Select]
: -REFEDIT
Select reference:
Select nesting level [Ok/Next] <Next>: n
Select nesting level [Ok/Next] <Next>: n
Select nesting level [Ok/Next] <Next>: n
Select nesting level [Ok/Next] <Next>: ok
Enter entity selection method [All/Nested] <All>: all
Display attribute definitions [Yes/No] <No>: y
Use REFCLOSE or the Refedit toolbar to end reference editing session.

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #22 on: September 07, 2016, 08:38:22 PM »
Hi Dan. I did as you suggested.  I added "-refedit" instead of "refedit" to both your previous & current combined LISP.

It now goes into the block, but unfortunately no matter the number of "N" i put in the LISP, it will still go into Block 4 instead of Block 5.  :grumpy:

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #23 on: September 07, 2016, 10:27:08 PM »
can you get the command line to work by just typing: -refedit > (select) > n > n > etc?

perhaps the command sequence is different between your acad and bricscad

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #24 on: September 08, 2016, 01:32:04 AM »
Hi Dan.

What do you make out of this?

Only the command in 2nd photo works.

- Both instances I click the lower right square.
- In the first photo, I get to Block 4 instead & it is on the upper left.
- In the 2nd photo, instead of ALL, I need to choose NESTED & select all the items which get to the block 5 that i want.
(So means no way for a LISP to automatically bring me to Block 5?)



« Last Edit: September 08, 2016, 01:38:31 AM by ctrlaltdel »

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #25 on: September 08, 2016, 01:52:05 AM »
I don't know, if the only way it works is to select nested objects, then I think lisp won't work. And if there is no way you can get the desired outcome by manually typing commands, I also don't think lisp will work for you. My last suggestion is just to double check options on number of "n" before OK to get desired nesting, in my test I had a hard time due to highlight not being clear and it was one less than I expected. From your output, block 5 is nest level 2, which I think would be just zero or one "n", not two as you show.

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #26 on: September 08, 2016, 08:46:02 PM »
I don't know, if the only way it works is to select nested objects, then I think lisp won't work. And if there is no way you can get the desired outcome by manually typing commands, I also don't think lisp will work for you. My last suggestion is just to double check options on number of "n" before OK to get desired nesting, in my test I had a hard time due to highlight not being clear and it was one less than I expected. From your output, block 5 is nest level 2, which I think would be just zero or one "n", not two as you show.

Hi Dan. I tried from no "N", 1 "N", 2 "N"........all the way to 16 "N". Not able to get into Block 5. I do not know what is the problem.

danallen

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #27 on: September 08, 2016, 10:44:47 PM »
well I'm out of suggestions. I tested on your drawing and picked lower right square and it worked in Bricscad v14

my test dwg file is attached, using xs01 lisp > picking the 5 then REFEDITS the level 4 block

ctrlaltdel

  • Guest
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #28 on: September 10, 2016, 02:37:51 AM »
well I'm out of suggestions. I tested on your drawing and picked lower right square and it worked in Bricscad v14

my test dwg file is attached, using xs01 lisp > picking the 5 then REFEDITS the level 4 block

Thank for all the help dan.  Nice idea of th numbering block. 

T.Willey

  • Needs a day job
  • Posts: 5251
Re: LISP to access Block level outside of another block of a clicked entity?
« Reply #29 on: September 10, 2016, 01:59:39 PM »
I just cannot pass up a challenge, when I have time.  And since dan allen worked so hard to try and help, I figured I would post a solution that works in AutoCAD.  It may not be the only way, but it is a way that worked on my testing of the drawing provided.

Code: [Select]
(defun c:test (/ sel)
    (setq sel (nentsel))
    (command "_.-refedit" (cadr sel))
    (repeat (- (length (last sel)) 2) (command "_next"))
    (command "_ok" "_All" "_No")
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.