BRICSCAD - need help with lisp to number blocks by type and put the number to an attribute (existing lisp, *U type problem)

BRICSCAD - need help with lisp to number blocks by type and put the number to an attribute (existing lisp, *U type problem)

aridzv
Enthusiast Enthusiast
761 Views
11 Replies
Message 1 of 12

BRICSCAD - need help with lisp to number blocks by type and put the number to an attribute (existing lisp, *U type problem)

aridzv
Enthusiast
Enthusiast

Hi.

I have a lisp that number blocks by their type (see attached lisp).

the problem is that:

when there are dynamic blocks (*U type) the lisp take them by the *U name and not by the block name,

and then the same type of blocks get different numbers.

I also attached a sample drawing that show the problem.

hope that someone will be able to help.

thanks,

aridzv

 

 

 

[ The subject line of this post has been edited for clarity by @pendean : Added Software Name ]

0 Likes
762 Views
11 Replies
Replies (11)
Message 2 of 12

komondormrex
Mentor
Mentor

hi,

replace (setq bname (cdr (assoc 2 ent)))

with (setq bname (vla-get-effectivename (vlax-ename->vla-object (cdr (assoc - 1 ent))))) 

0 Likes
Message 3 of 12

aridzv
Enthusiast
Enthusiast

@komondormrex  Hi and thanks for the reply.

I'm getting this error massage:

; ----- LISP : Call Stack -----
; [0]...C:BLOCKS_NUMBERING_BY_TYPE <<--
;
; ----- Error around expression -----
; (VLE-CDRASSOC - 1 ENT)

0 Likes
Message 4 of 12

komondormrex
Mentor
Mentor

this is not autocad you're using? there are problems with your dynamic blocks in autocad.

0 Likes
Message 5 of 12

aridzv
Enthusiast
Enthusiast

@komondormrex 

bricscad

0 Likes
Message 6 of 12

pendean
Community Legend
Community Legend

@aridzv wrote:

bricscad


Why don't you participate in their user forums, there is even a LISP topic one

https://forum.bricsys.com/ 

Message 7 of 12

komondormrex
Mentor
Mentor

that's it. seems lisp in autocad and bricscad are not fully compatible. 

Message 8 of 12

aridzv
Enthusiast
Enthusiast
I am a user over there and I did post a question about a possible incompetabilities in lisp code.
Hope I get an answer.
0 Likes
Message 9 of 12

Sea-Haven
Mentor
Mentor

The issue is not in incompatibility as I use Bricscad every day rather go back 1 step, does block have an Effective name ? You can have blocks with the name *U123 but they have no effective name. Maybe created by copying from another dwg. Answered this about 1/2 hour ago on another forum.

 

(vlax-property-available-p obj "Effectivename")

  

0 Likes
Message 10 of 12

aridzv
Enthusiast
Enthusiast

@Sea-Haven 

Close but not quite...
I share the final code to close this topic,
thanks to all that helped.

 

(defun c:Blocks_Numbering_By_Type6 ( / ss ent ent_n bname lst lst2 x y val val2 pointmin pointmax bobj mp)
(vl-load-com)
(setvar 'textstyle "standard")
(prompt "select blocks")
(setq ss (ssget '((0 . "INSERT"))))

(if (= ss nil)
(alert "No blocks selected ")
(progn
(setq lst '())
      (repeat (setq x (sslength ss))
        (setq ent_n (ssname ss (setq x (1- x)))
              ent (entget ent_n)
        )    
       
 (setq bname (cdr (assoc 2 ent)))
 (setq obj2 (vlax-ename->vla-object ent_n))
 (setq bname (getpropertyvalue ent_n "EffectiveName~Native"))
 (setq ent (cdr (assoc -1 ent)))
 (setq lst (cons (list bname ent) lst))
)
(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
                                             
(setq lst2 '())
(setq x 0 y 1)
(repeat (length lst)
(if (= (car (nth x lst)) (car (nth (1+ x) lst)))
  (setq lst2 (cons (list (car (nth x lst)) (cadr (nth x lst)) y) lst2))
  (progn 
  (setq lst2 (cons (list (car (nth x lst))(cadr (nth x lst)) y) lst2))
  (setq y (1+ y))
  )
)
(setq x (1+ x))
)
  
(foreach blk lst2
  (setq ent (cadr blk))
  (princ ent)
  (setq bobj (vlax-ename->vla-object ent))
  (princ bobj)
  ;;(vla-GetBoundingBox bobj 'minpoint 'maxpoint)
  ;;(setq pointmin (vlax-safearray->list minpoint))
  ;;(setq pointmax (vlax-safearray->list maxpoint))
  ;;(setq mp (mapcar '* (mapcar '+ pointmin pointmax) '(0.5 0.5)))
  ;;(command "text" mp 1.0 0.0 (nth 2 blk))
  (LM:vl-setattributevalue bobj "ORDER" (rtos (nth 2 blk)) )
)
                                             
)
)
(princ)


)

(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

 

 

 

 

0 Likes
Message 11 of 12

Sea-Haven
Mentor
Mentor

Very interesting using getpropertyvalue, the function of getproperty was introduced in more recent versions of Bricscad, its not supported in my V20. Waiting for rainy cash day and will upgrade to current version.

0 Likes
Message 12 of 12

aridzv
Enthusiast
Enthusiast

@Sea-Haven 

upgrade from V-20 to the upcoming V-24?...

you will need a mild tropicl storm...😁

0 Likes