Jump to content

count blocks & set lookup1


pmxcad

Recommended Posts

Hello lisp artists,

need some help with these lisps, I want to automatically set the cable tags (block "kabeltype A or B") in the attached drawing.

The lisp should count the blocks in a range than set the lookup1 from the "kabeltype A or B" block.

Lisp "test1" counts the blocks in a range. (does not work well, counts more blocks).

Lisp "test2" set the "lookup1" table of selected block (block "kabeltype A or B") (this should go automatically).

All cabletags have the attribute "TEXT1" and have the value of the first value of a module (EIDS, ETV or I / O).

Can someone help me with these lisps, especially at the first (test1) for counting the blocks ...

 

(defun c:test1 ()
(defun filter_set (blk tag lo hi / ss olst)
 (vl-load-com)
 (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blk) (cons 66 1))))
   (foreach blk (mapcar 'cadr (ssnamex ss))
     (foreach att (vlax-invoke (vlax-ename->vla-object blk) 'getattributes)
   (and (eq tag (vla-get-tagstring att))
        (not (<= lo (atof (vla-get-textstring att)) hi))
        (ssdel blk ss)
   )
     )
   )
 )
 ss
)
(sssetfirst nil (filter_set "Sab-kast,U00009,U00017,U00028,U00039" "TEXT1"1001 1006))
(setq ss (ssget "P"))
(setq count (sslength ss))
(alert (itoa count))
)

 

(defun c:test2 (/ en eo dblist dbprop)
 (setq en (entsel))
 (setq eo (vlax-ename->vla-object (car en)))
 (setq dblist (vlax-invoke eo 'GetDynamicBlockProperties))
 (foreach dbprop dblist
   (if (= (vla-get-PropertyName dbprop) "Lookup1")
       (vlax-put dbprop 'Value "8")))
)

 

 

 

thanks in advance

 

PmxCAD

Opt1.dwg

Link to comment
Share on other sites

...

All cabletags have the attribute "TEXT1" ....

 

Here's a quick one to get you started.

(defun c:foo (/ ss)
 (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1))))
   (foreach b (mapcar 'cadr (ssnamex ss))
     (if (null	(vl-some '(lambda (x) (= "TEXT1" (vla-get-tagstring x)))
		 (vlax-invoke (vlax-ename->vla-object b) 'getattributes)
	)
  )
(ssdel b ss)
     )
   )
 )
 (sssetfirst nil ss)
 (princ)
)

Link to comment
Share on other sites

ronjonp, Thanks for your anwser.

I'm not that good with lisp. I Can change it a bit and do some modifications.

As far as your lisp is concerned, it selects all the blocks with the tag TEXT1.

I'm not sure how I should apply it. I tried it in the existing lisp, but then the result remains the same, it counts all blocks (13) and yours lisp select everything.

 

PmxCAD

Link to comment
Share on other sites

My $0.05 which may not be right need a dwg to test.

 

(defun c:foo (/ ss)
(setq count 0)
 (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "Sab-kast,U00009,U00017,U00028,U00039") '(66 . 1))))
; count could be added into foreach (setq count (+ count 1))

Link to comment
Share on other sites

dynamic blocks? -> get effective name

 

is not necessary if dynamic blocks are not yet changed. you can select them as regular blocks. they are not yet Anonymous.

Link to comment
Share on other sites

Almost working,

Have a problem with the selection in "test3". Want to select the previous selection with entlast. I'm still playing around with the entsel or entlast. Do not get it working.

Does anyone have a suggestion?

 

(defun c:test1 (); Lee Mac
(defun filter_set (blk tag lo hi / ss olst)
 (vl-load-com)
 (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blk) (cons 66 1))))
   (foreach blk (mapcar 'cadr (ssnamex ss))
     (foreach att (vlax-invoke (vlax-ename->vla-object blk) 'getattributes)
   (and (eq tag (vla-get-tagstring att))
        (not (<= lo (atof (vla-get-textstring att)) hi))
        (ssdel blk ss)
))))
 ss
)
(sssetfirst nil (setq sset (filter_set "Sab-kast,U00009,U00017,U00028,U00039" "TEXT1"1001 1006)))

   (princ (strcat "\n "(itoa (sslength sset))" items selected"))
 (princ)

(setq count (sslength sset))
(setq set (itoa count))
;(alert set)
)

;---------------------------------------------------------------------------------------------------


(defun c:test2 ( / att atx ent idx sel str ) ;Lee Mac
   (if (/= "" (setq str "1001"))
       (if (and
               (setq sel
                   (ssget "_X"
                       (list '(0 . "INSERT") '(2 .  "kabeltype B")
                           (if (= 1 (getvar 'cvport))
                               (cons 410 (getvar 'ctab))
                              '(410 . "Model")
                           ))))
               (progn
                   (repeat (setq idx (sslength sel))
                       (setq ent (ssname sel (setq idx (1- idx)))
                             att (entnext ent)
                             atx (entget  att)
                       )
                       (while
                           (and (= "ATTRIB" (cdr (assoc 0 atx)))
                                (not (wcmatch (strcase (cdr (assoc 1 atx))) str))
                           )
                           (setq att (entnext att)
                                 atx (entget  att)
                           ))
                       (if (= "SEQEND" (cdr (assoc 0 atx)))
                           (ssdel ent sel)
                       ))
                   (< 0 (sslength sel))
               ))
           (sssetfirst nil sel)
           (princ (strcat "\nNo blocks found with attribute value matching \"" str "\"."))
       )
   )
   (princ)
)

;---------------------------------------------------------------------------------------------------


(defun c:test3 (/ en eo dblist dbprop)
  (setq en (entlast))
 ;(setq en (entsel))
 (setq eo (vlax-ename->vla-object (car en)))
 (setq dblist (vlax-invoke eo 'GetDynamicBlockProperties))
 (foreach dbprop dblist
   (if (= (vla-get-PropertyName dbprop) "Lookup1")
       (vlax-put dbprop 'Value set)))
)

;---------------------------------------------------------------------------------------------------

(defun c:cable ()
(c:test1)
(c:test2)
(c:test3)
)


Opt1.dwg

Link to comment
Share on other sites

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...