Author Topic: Setting variable name to an already selected object  (Read 4653 times)

0 Members and 1 Guest are viewing this topic.

2cook2

  • Guest
Setting variable name to an already selected object
« on: January 16, 2014, 04:34:59 PM »
I am writing a routine to move everything in a drawing from the insertion point of an "altered" dynamic block to 0,0,0.  I am using Lee Mac's "Get Anonymous References" subfunction (getblockselection) to find the "altered" dynamic block.

It finds the block and highlights it.  Then it gives me the following error:

"bad argument type: lentityp (nil <Selection set: 7e1d>)"

How do I assign the variable "bim" to the already selected object?

Thanks
ScottL.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mpp2 (/ bim blk xyz)
  2.  
  3.   (setvar "cmdecho" 0)
  4.  
  5.   (command "erase" "All" "")                                                    ;Erase template drawing text
  6.  
  7.   (c:on)                                                                        ;Turn osnaps on
  8.  
  9.   (command "Pasteclip" "0,0,0")                                                 ;Paste model
  10.  
  11.   (setq blk "BIM_Origin+")                                                      ;Set variable to block name
  12.   (sssetfirst nil (getblockselection blk))                                      ;Selects BIM_Origin+ block
  13.   (princ)
  14.   (setq bim (entget blk))
  15.   (setq xyz (cdr
  16.               (assoc 10
  17.                      (entget (ssname (ssget "_X" '((2 . bim))) 0))
  18.               ) ;_ End assoc
  19.             ) ;_ End cdr
  20.   )                                                                             ;Find insertion point of BIM Origin block
  21.  
  22.   (command "move" "all" "" xyz "0,0,0")
  23.  
  24.   (command "_-vports" "2" "V")                                                  ;Viewport 2 (Vertical)
  25.   (command "_-view" "_swiso")                                                   ;
  26.   (command "_vscurrent" "Realistic")                                            ;
  27.   (command "zoom" "E" "zoom" ".90x")                                            ;
  28.   (command "cvport" "3")                                                        ;
  29.   (command "zoom" "E" "zoom" ".90x")                                            ;
  30.  
  31.   (setvar "cmdecho" 1)
  32.  
  33. ) ;_ end of defun
  34.  
  35.  
  36. ;;--Subroutine---------------------------------------------------------------------------------------------------
  37.  
  38.  
  39. ;; Get Anonymous References  -  Lee Mac
  40. ;; Returns the names of all anonymous references of a block.
  41. ;; blk - [str] Block name for which to return anon. references
  42.  
  43. (defun lm:getanonymousreferences (blk / ano def lst rec ref)
  44.   (setq blk (strcase blk))
  45.   (while (setq def (tblnext "block" (null def)))
  46.     (if
  47.       (and (= 1 (logand 1 (cdr (assoc 70 def))))
  48.            (setq rec
  49.                   (entget
  50.                     (cdr
  51.                       (assoc 330
  52.                              (entget
  53.                                (tblobjname
  54.                                  "block"
  55.                                  (setq ano (cdr (assoc 2 def)))
  56.                                ) ;_ End tblobjname
  57.                              ) ;_ End entget
  58.                       ) ;_ End assoc
  59.                     ) ;_ End cdr
  60.                   ) ;_ End entget
  61.            ) ;_ End setq
  62.       ) ;_ End and
  63.        (while
  64.          (and
  65.            (not (member ano lst))
  66.            (setq ref (assoc 331 rec))
  67.          ) ;_ End and
  68.           (if
  69.             (and
  70.               (entget (cdr ref))
  71.               (= blk (strcase (lm:al-effectivename (cdr ref))))
  72.             ) ;_ End and
  73.              (setq lst (cons ano lst))
  74.           ) ;_ End if
  75.           (setq rec (cdr (member (assoc 331 rec) rec)))
  76.        ) ;_ End while
  77.     ) ;_ End if
  78.   ) ;_ End while
  79.   (reverse lst)
  80. ) ;_ End defun
  81.  
  82. ;; Effective Block Name  -  Lee Mac
  83. ;; ent - [ent] Block Reference entity
  84.  
  85. (defun lm:al-effectivename (ent / blk rep)
  86.   (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
  87.     (if
  88.       (and
  89.         (setq rep
  90.                (cdadr
  91.                  (assoc -3
  92.                         (entget
  93.                           (cdr
  94.                             (assoc 330
  95.                                    (entget
  96.                                      (tblobjname "block" blk)
  97.                                    ) ;_ End entget
  98.                             ) ;_ End assoc
  99.                           ) ;_ End cdr
  100.                           '("AcDbBlockRepBTag")
  101.                         ) ;_ End entget
  102.                  ) ;_ End assoc
  103.                ) ;_ End cdadr
  104.         ) ;_ End setq
  105.         (setq rep (handent (cdr (assoc 1005 rep))))
  106.       ) ;_ End and
  107.        (setq blk (cdr (assoc 2 (entget rep))))
  108.     ) ;_ End if
  109.   ) ;_ End if
  110.   blk
  111. ) ;_ End defun
  112.  
  113. (defun getblockselection (blk)
  114.   (ssget "_X"
  115.          (list '(0 . "INSERT")
  116.                (cons 2
  117.                      (apply 'strcat
  118.                             (cons blk
  119.                                   (mapcar '(lambda (x) (strcat ",`" x))
  120.                                           (lm:getanonymousreferences blk)
  121.                                   ) ;_ End mapcar
  122.                             ) ;_ End cons
  123.                      ) ;_ End apply
  124.                ) ;_ End cons
  125.          ) ;_ End list
  126.   ) ;_ End ssget
  127. ) ;_ End defun
  128.  
  129.  
  130. ;;--End Subroutine-----------------------------------------------------------------------------------------------
  131.  
  132.  


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Setting variable name to an already selected object
« Reply #1 on: January 16, 2014, 05:08:09 PM »
Your error is here:
Code: [Select]
  (setq blk "BIM_Origin+")    ;Set variable to block name
 (sssetfirst nil (getblockselection blk))    ;Selects BIM_Origin+ block
 (princ)
 (setq bim (entget blk))  <------<<<
the variable blk is a string
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

2cook2

  • Guest
Re: Setting variable name to an already selected object
« Reply #2 on: January 16, 2014, 06:23:00 PM »
OK.  I see where that is the the text string "BIM_Origin+".

So how do I assign the variable "bim" to the selection set that is returned by  "getblockselection"?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Setting variable name to an already selected object
« Reply #3 on: January 16, 2014, 06:33:29 PM »
How do I assign the variable "bim" to the selection set that is returned by  "getblockselection"?

You can use:
Code: [Select]
(setq bim (getblockselection blk))

2cook2

  • Guest
Re: Setting variable name to an already selected object
« Reply #4 on: January 16, 2014, 07:09:46 PM »
Now I get the error:

bad SSGET list value

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mpp2 (/ bim blk xyz)
  2.   (prompt "[LISP - MEP Model Prep Part 2]")
  3.  
  4. ;;;  (setvar "cmdecho" 0)
  5. ;;;
  6. ;;;  (command "erase" "All" "")                                                 ;Erase template drawing text
  7. ;;;
  8. ;;;  (c:on)                                                                     ;Turn osnaps on
  9. ;;;
  10. ;;;  (command "Pasteclip" "0,0,0")                                                      ;Paste model
  11.  
  12.   (setq blk "BIM_Origin+")                                                      ;Set variable to block name
  13.   (setq bim (getblockselection blk))                                            ;Selects BIM_Origin+ block
  14.   (princ)
  15.   (setq xyz (cdr
  16.               (assoc 10
  17.                      (entget (ssname (ssget "_X" '((2 . bim))) 0))
  18.               ) ;_ End assoc
  19.             ) ;_ End cdr
  20.   )                                                                             ;Find insertion point of BIM Origin block
  21.  
  22.   (command "move" "all" "" xyz "0,0,0")
  23.  
  24.   (command "_-vports" "2" "V")                                                  ;Viewport 2 (Vertical)
  25.   (command "_-view" "_swiso")                                                   ;
  26.   (command "_vscurrent" "Realistic")                                            ;
  27.   (command "zoom" "E" "zoom" ".90x")                                            ;
  28.   (command "cvport" "3")                                                        ;
  29.   (command "zoom" "E" "zoom" ".90x")                                            ;
  30.  
  31.   (setvar "cmdecho" 1)
  32.  
  33. ) ;_ end of defun
  34.  

The subroutines are still in the original file, I didn't think they needed to be reposted.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Setting variable name to an already selected object
« Reply #5 on: January 17, 2014, 12:25:14 AM »
Change this :
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" '((2 . bim)))
  2.  

To this :
Code - Auto/Visual Lisp: [Select]
  1. bim
  2.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

2cook2

  • Guest
Re: Setting variable name to an already selected object
« Reply #6 on: January 17, 2014, 10:35:55 AM »
Thanks guys.  It now works like a charm.

ScottL

Code - Auto/Visual Lisp: [Select]
  1. (setq blk "BIM_Origin+")                                                        ;Set variable to BIM_Origin+ block name
  2.   (setq bim (getblockselection blk))                                            ;Find BIM_Origin+ block anonymous name
  3.   (princ)
  4.   (setq xyz (cdr                                                                ;Find insertion point of anonymous block
  5.               (assoc 10
  6.                      (entget (ssname bim 0))
  7.               ) ;_ End assoc
  8.             ) ;_ End cdr
  9.   ) ;_ End setq
  10.   (command "move" "all" "" xyz "0,0,0")                                         ;Move All to 0,0,0

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Setting variable name to an already selected object
« Reply #7 on: January 18, 2014, 02:08:23 PM »
Now I get the error:

bad SSGET list value

Aside from the fact that the variable bim points to a selection set rather than a string, to understand why this:
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" '((2 . bim)))
Would result in an error even if bim was a valid string, read this tutorial.

Lee