Need LISP routine to automatically place "number"-blocks on conveyors

Need LISP routine to automatically place "number"-blocks on conveyors

Anonymous
Not applicable
1,357 Views
11 Replies
Message 1 of 12

Need LISP routine to automatically place "number"-blocks on conveyors

Anonymous
Not applicable

Hi all 🙂

 

I have no coding experience or previous experience with LISP, so I sincerely ask for your help. I make a lot of layouts with conveyors - sometimes with several thousands of conveyors. When my layouts are done, I usually need several hours of placing a simple "numbering" block in the end-points of every conveyor.

 

Each conveyor consists of a basepoint, a length parameter and a regular "point" in the end.

The numbering block, consists of a basepoint and a strech-point to move the text back and forth.

 

I need a LISP routine that automatically takes the basepoint of the numbering block, and places it on top of the "point" in each conveyor in the layout, so that the only thing I have to do by myself, is move the text on the numbering block.

 

I attached an example DWG that explains what I need, and what it is supposed to look like when the LISP has done its job - I really hope that you can help me 🙂

 

If anything is unclear, please just ask 🙂

0 Likes
Accepted solutions (2)
1,358 Views
11 Replies
Replies (11)
Message 2 of 12

hak_vz
Advisor
Advisor

I don't have a time to write some code but I'll share my view on this task. I think this is solvable without writting a code. I've opened your sample drawing and as I see you've got conveyors blocks that you join to numbering.


I don't know, maybe I'm wrong, but I would joint those two blocks into a single dynamic block with rules about how to orient numbering in regards to conveyour orijentation (outside, at midpoint ....).

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 12

Anonymous
Not applicable

@hak_vz wrote:

I don't have a time to write some code but I'll share my view on this task. I think this is solvable without writting a code. I've opened your sample drawing and as I see you've got conveyors blocks that you join to numbering.


I don't know, maybe I'm wrong, but I would joint those two blocks into a single dynamic block with rules about how to orient numbering in regards to conveyour orijentation (outside, at midpoint ....).


That was my initial idea, to have the numbering block as a part of the conveyor block - but when i need to mirror a group of conveyors, the text would also be mirrored. Also, the blocks need to be as simple as possible, and rotating them with a rotate parameter instead of using the rotate tool or the rotation in the Properties menu would definately confuse my coworkers 🙂

0 Likes
Message 4 of 12

pbejse
Mentor
Mentor

Speaking of rotation, there's one odd block in that drawing at position X 10000, the rotation is 90 deg, while similar block definition with thb w  same rotation is at either 0 or 180, cant wrap my ahead around it. 

 

Are the conveyors rotation is either 0 or 90 and never at an odd angle?

 

 

0 Likes
Message 5 of 12

pbejse
Mentor
Mentor
Accepted solution

Q&D : You can build off this code..

 

(defun c:NOC (/  valid_blocks f ss i e data dpp len)
;;	pBe 2019	;;
  
(setq valid_blocks '("CONV-400x200" "CONV-600x400"));; Add more block names here with
(setq f (lambda (p) (vlax-get e p)))

(if 
      (setq ss (ssget '((0 . "INSERT")(2 . "`*U*,CONV-*"))))
      
  	(repeat (setq i (sslength ss))
          (setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))))
          (setq data (mapcar 'f  '("Insertionpoint" "Rotation" "EffectiveName" "XScaleFactor")))

          (if (and
                (member (caddr data) valid_blocks)
                (setq dpp (mapcar '(lambda (e) (mapcar 'f
                                      '("PropertyName" "Value" )))
                                    (vlax-invoke e 'GetDynamicBlockProperties)))
                (> (setq len (cadr (Assoc "Length" dpp))) 0)
                )
		(vlax-invoke
		  (vlax-get (vla-get-ActiveLayout
		              (vla-get-activedocument
		                (vlax-get-acad-object)
		              )
		            )
		            'Block
		  )
		  'InsertBlock
		  (polar (car data)
                         (+ (if (minusp (last data)) pi 0.0) (Cadr data))
                         len)
		  "UnitNumber"	;; make sure this block exists in the drawing
		  1 1 1 0) ;; <-- block rotation at 0, Zero, cero, Null, bokya, nialas ....
		)
            )
          )
  (princ)
  )

HTH

 

 

Message 6 of 12

Anonymous
Not applicable

@pbejse wrote:

Q&D : You can build off this code..

 

HTH

 

 


Code did EXACTLY what it was supposed to do - thank you so much!!! 🙂 Kudos!

 

Regarding the "weird" block you mentioned, if you orbit the drawing, you'll see that the block was 3d rotated 🙂

0 Likes
Message 7 of 12

pbejse
Mentor
Mentor

@Anonymous wrote:


Code did EXACTLY what it was supposed to do - thank you so much!!! 🙂 Kudos!

Regarding the "weird" block you mentioned, if you orbit the drawing, you'll see that the block was 3d rotated 🙂


 

Glad to be of help KayChrisKAy.

I see, now why didn't I think of  that 😄

 

Cheers

 

 

 

0 Likes
Message 8 of 12

Anonymous
Not applicable

@pbejse wrote:

@Anonymous wrote:


Code did EXACTLY what it was supposed to do - thank you so much!!! 🙂 Kudos!

Regarding the "weird" block you mentioned, if you orbit the drawing, you'll see that the block was 3d rotated 🙂


 

Glad to be of help KayChrisKAy.

I see, now why didn't I think of  that 😄

 

Cheers

 


Additional question - I apologize... 🙂 Is it somehow possible to, instead of defining all 50 blocks that I got, that start with "CONV-", to just setq valid_blocks to all blocks that has a name starting with "CONV-"?

0 Likes
Message 9 of 12

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

estion - I apologize... 🙂 Is it somehow possible to, instead of defining all 50 blocks that I got, that start with "CONV-", to just setq valid_blocks to all blocks that has a name starting with "CONV-"?

Yup.

 

Replace

(member (caddr data) valid_blocks)

with

(vl-string-search "CONV-" (caddr data))

HTH

 

0 Likes
Message 10 of 12

Anonymous
Not applicable

I feel stupid for asking a 3rd time, I'm very sorry! 😥

 

The lisp works great, but how do I add blocks to the routine that doesn't start with "CONV-"?

 

(defun c:NOC (/  valid_blocks f ss i e data dpp len)
;;	pBe 2019	;;
  
(setq valid_blocks '("CONV-400x200" "CONV-600x400" "TRANSF-400x200" "OVERH-400x200"));; Add more block names here with
(setq f (lambda (p) (vlax-get e p)))

(if 
      (setq ss (ssget '((0 . "INSERT")(2 . "`*U*,CONV-*")))) ;;I assume I have to add something here
      
  	(repeat (setq i (sslength ss))
          (setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))))
          (setq data (mapcar 'f  '("Insertionpoint" "Rotation" "EffectiveName" "XScaleFactor")))

          (if (and
                ;;(member (caddr data) valid_blocks)
		(vl-string-search "CONV-" (caddr data)) ;;And also something here?
                (setq dpp (mapcar '(lambda (e) (mapcar 'f
                                      '("PropertyName" "Value" )))
                                    (vlax-invoke e 'GetDynamicBlockProperties)))
                (> (setq len (cadr (Assoc "Length" dpp))) 0)
                )
		(vlax-invoke
		  (vlax-get (vla-get-ActiveLayout
		              (vla-get-activedocument
		                (vlax-get-acad-object)
		              )
		            )
		            'Block
		  )
		  'InsertBlock
		  (polar (car data)
                         (+ (if (minusp (last data)) pi 0.0) (Cadr data))
                         len)
		  "POSITION2"	;; make sure this block exists in the drawing
		  1 1 1 0) ;; <-- block rotation at 0, Zero, cero, Null, bokya, nialas ....
		)
            )
          )
  (princ)
  )

This is the absolute last I need 🙂

 

Can you please help - I hope it's not too much trouble

0 Likes
Message 11 of 12

pbejse
Mentor
Mentor

ITs not too much trouble, we will target blocks with this pattern "###x###" at the end of the block name similar to any of these "CONV-600x400" "TRANSF-400x200" "OVERH-600x200", also it should have the "LENGTH" property name.

 

It would also help if you you can define which blocks to insert in place of "UnitNumber" or "POSITION2" etc.. that way you dont need to change the block name to insert everytime you need to run the program. Perhaps we can just define one for each block like this:

 

(Defun c:iBlock1 nil (NOC "UnitNumber"))
(Defun c:iBlock2 nil (NOC "POSITION2"))

you can add as many as you  like

Then we modify the main routine to accept any valid block name as an argument

 

(defun NOC ( bname /  valid_blocks f ss i e data dpp len)
;;	pBe 2019	;;
  (setq f (lambda (p) (vlax-get e p)))

(if 
      (setq ss (ssget '((0 . "INSERT")(2 . "`*U*,*###x###*"))))       
  	(repeat (setq i (sslength ss))
          (setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))))
          (setq data (mapcar 'f  '("Insertionpoint" "Rotation" "EffectiveName" "XScaleFactor")))

          (if (and
                (wcmatch (strcase (caddr data)) "*###X###*")
                (setq dpp (mapcar '(lambda (e) (mapcar 'f
                                      '("PropertyName" "Value" )))
                                    (vlax-invoke e 'GetDynamicBlockProperties)))
                (> (setq len (cadr (Assoc "Length" dpp))) 0)
                )
		(vlax-invoke
		  (vlax-get (vla-get-ActiveLayout
		              (vla-get-activedocument
		                (vlax-get-acad-object)
		              )
		            )
		            'Block
		  )
		  'InsertBlock
		  (polar (car data)
                         (+ (if (minusp (last data)) pi 0.0) (Cadr data))
                         len)
		         bname		
		  1 1 1 0) 
		)
            )
          )
  (princ)
  )

 

 

HTH

 

 

 

 

 

0 Likes
Message 12 of 12

Anonymous
Not applicable

Never mind the "Position2", the block to be inserted is only called "UnitNumber".

 

I have another issue now - I want the LISP to also add the block to three different blocks that is not being defined by the "###x###", but still have the Length parameter. They are also conveyors, but their names are simply "AUFK-xxx", "BIxxA-KN2" and "REV-xxxx"

0 Likes