Cannot get the correct block name from the selection set

Cannot get the correct block name from the selection set

Anonymous
Not applicable
640 Views
3 Replies
Message 1 of 4

Cannot get the correct block name from the selection set

Anonymous
Not applicable

1.PNG

 

I''m writing a script to export a grid layout (example shown in the image above) into a text file. Everything else is now working correctly, but somehow the script grabs a wrong block name (which seems like a temporary name) for one of my selection statement, screwing everything up (marked as red bold below).

  ;; For each grid, traverse through each cell to check if panel exists inside
;; Create an 2d array to mark the occupancy (of panels) for each grid
(setq n gridtot tmpset gridset) (while (> n 0) (setq n (1- n) row (caadar tmpset) y (- (cadaar tmpset) (/ *distver 2)) resultgrid nil ) (while (> row 0) (setq row (1- row) col (car (cdadar tmpset)) x (+ (caaar tmpset) (/ *disthor 2)) resultrow nil ) ;; For each cell in the row, grab all blocks inside the area to detect the ;; specified block (given as *blkname) ;; Insert 1 (true) for each occupied cell, and 0 (false) for unoccupied cell (while (> col 0) (setq col (1- col) fp (list (- x (/ *disthor 2.2)) (- y (/ *distver 2.2))) sp (list (+ x (/ *disthor 2.2)) (+ y (/ *distver 2.2))) ssp (ssget "_C" fp sp '((0 . "INSERT"))) ssl (cond (ssp (sslength ssp)) (0)) found nil ) (while (> ssl 0) (setq ssl (1- ssl) blkname (cdr (assoc 2 (entget (ssname ss ssl)))) ) (if (= blkname *blkname) (setq found T) ) ) (if found (setq resultrow (append '(1) resultrow)) (setq resultrow (append '(0) resultrow)) ) ) (setq resultgrid (cons resultrow resultgrid) y (- y *distver) ) ) )

The red block that I'm trying to detect is named as "SDA_PANEL". However, when I am debugging, the script picks it up as "*U8" (see images below).

Capture.PNG2.PNG

 

How would I be able to resolve this?

 

 

P.S.

Is it a good practice to add a few lines at the top to save all system variables, then to load it back at the bottom?

 

0 Likes
Accepted solutions (1)
641 Views
3 Replies
Replies (3)
Message 2 of 4

hmsilva
Mentor
Mentor
Accepted solution

Hi Edmond,

try to change

(setq ssl     (1- ssl)
      blkname (cdr (assoc 2 (entget (ssname ss ssl))))
)

to

 

(setq ssl     (1- ssl)
      blkname (vla-get-effectivename (vlax-ename->vla-object  (ssname ss ssl)))
)

and add (vl-load-com) to your code, if required.

 

 

'Is it a good practice to add a few lines at the top to save all system variables, then to load it back at the bottom?'

 

If in your code you are changing System Variables, yes!

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 4

Anonymous
Not applicable

First time, I thought it had worked.

However, when I ran it back with other layouts, it seems like it's ignoring the block name that I specify.

In other words, if there were any blocks in the selection set, the "found" will automatically be set to T.

 

I haven't used any vl command before, so I'm not sure what to do.

 

0 Likes
Message 4 of 4

hmsilva
Mentor
Mentor

@Anonymous wrote:

First time, I thought it had worked.

However, when I ran it back with other layouts, it seems like it's ignoring the block name that I specify.

...


Hi Edmond,

 

the test

(= blkname *blkname)

is case sensitive, try modifying the test to

(= (strcase blkname) (strcase *blkname))

 

Hope this helps,
Henrique

EESignature

0 Likes