Drawinghead and bom transfer...

Drawinghead and bom transfer...

ekjerside
Contributor Contributor
439 Views
2 Replies
Message 1 of 3

Drawinghead and bom transfer...

ekjerside
Contributor
Contributor

Hey

We are getting some drawings from another company that has Drawings head blocks and BOM blocks inside the file.
We need to transfer the data from this blocks to our blocks. I know this can be done by writing a Lisp script to do the job.

Please help:

I need a lisp script that do the following....

1. Find the block name 'STDHOVED225' remember its insertion point and

insert the block 'BWRS_HOVED' at that insertsertion point.
2. Transfer the data from the block name 'STDHOVED225' to the Block name 'BWRS_HOVED' in the bellow showed tags.

---------------------------------------------------------------------------------
Blockname: STDHOVED225  Transfer to Blockname: BWRS_HOVED

Attribut tag                                                 Attribut tag

TEGN1                                                          DESCRIPTION
TEGN2                                                          TITEL
TEGN2                                                          SUBJECT
SERIENO                                                     SERIAL
---------------------------------------------------------------------------------

3. Delete the block named 'STDHOVED225' from the drawing.
4. Find the block name 'styklistefelt' remember its insertion point and insert the block 'Part list top'
5. Transfert the Data from block name 'styklistefelt' to the block name 'BWRS_HOVED' in the bellow showed tags.

---------------------------------------------------------------------------------
Blockname: styklistefelt     Transfer to Blockname: BWRS_HOVED

Attribut tag                                               Attribut tag

TOTALWEIGHT                                           TOTAL
TIMES                                                         QUANTITY
---------------------------------------------------------------------------------

6. Transfert the Data from block name 'styklistefelt' to the block name 'Part list top' in the bellow showed tags.

---------------------------------------------------------------------------------
Blockname: styklistefelt     Transfer to Blockname: Part list

Attribut tag                                               Attribut tag

PCS                                                             Qty.
DESCRIPTION                                           Description
ITEM                                                           Item
AXXXX-X-XXXXA                                      Drg.
MATERIAL                                                 Material
CODE                                                          Cert
WEIGHT                                                     Weight
---------------------------------------------------------------------------------

7. Count the numbers of items in BOM from the blocks named styklistefelt and Ekstrastykliste. The numbers of BOM items is taken from tags ITEM in the blocksnamed 'styklistefelt' and 'Ekstrastykliste'. this is need in the next step.
8. Find the block name 'Ekstrastykliste' remember its insertion point and its tag 'ITEM' number and insert and replace with the block name 'Part list top' and transfer the below Data from the block named 'Ekstrastykliste' to 'Part list top'.

----------------------------------------------------------------------------------
Blockname: Ekstrastykliste      Transfer to Blockname: Part list top

Attribut tag                                                     Attribut tag

PCS                                                                   Qty.
DESCRIPTION                                                 Description
ITEM                                                                Item
AXXXX-X-XXXXA                                            Drg.
MATERIAL                                                       Material
CODE                                                               Cert
WEIGHT                                                           Weight
---------------------------------------------------------------------------------

9. Repeat the process from 8. until the TWO BOMS are indentical.
10. Delete all the 'Ekstrastyklistefelt' and 'Styklistefelt' blocks.

 

I have attached a exampel dwg. In modelspace i showed where the tags data value has to be transfer from block to block. In paperspace i have showed and exampel of the two Drawingheads and Boms.

 

I have also attached a description and the below code. 

 

I have start a of lisp script, just need help to be changede to the upper description, thank you very much in advance:

 

(defun c:DH2DH ( / ACTLYT ATTLST ATTLST1 ATTS ENT HND I LYT OBJ OBJ1 OLD_LST OLD_REC POS RT S1 S2 SC)
  (vl-load-com)
  (setq atts    '(("TEGN1" "DESCRIPTION") ("TEGN2" "TITEL") ("TEGN3" "SUBJECT") ("SKA1" "SCALE"))
	old_rec (getvar 'ATTREQ)
	atclyt (getvar 'CTAB))
  (setvar 'ATTREQ 0)
  (if (setq s1 (ssget "_X" '((0 . "INSERT") (2 . "STDHOVED224") (66 . 1))))
     (repeat (setq i (sslength s1))
        (setq hnd (ssname s1 (setq i (1- i)))
	      ent (entget hnd)
	      lyt (cdr (assoc 410 ent))
	      sc (cdr (assoc 41 ent))
	      rt (* (/ (cdr (assoc 50 ent)) pi) 180.0)
	      attlst nil
	      attlst1 nil
	      obj (vlax-ename->vla-object hnd)
	      attlst (vlax-invoke obj 'GetAttributes)
      )setq
      (foreach att attlst
	(setq old_lst (cons (list (vla-get-TagString att) (vla-get-TextString att)) old_lst))
      )foreach
       (setvar 'CTAB lyt)
      (vl-cmdf "_.-insert" "BWRS_HOVED" "_NONE" (vlax-get obj 'InsertionPoint) sc sc rt)
      (if (setq s2 (ssget "_L" '((0 . "INSERT") (2 . "BWRS_HOVED") (66 . 1))))
	(progn
	  (setq	obj1	(vlax-ename->vla-object (ssname s2 0))
		attlst1	(vlax-invoke obj1 'GetAttributes)
	  );; setq
	  (foreach att attlst1
	    (if	(setq pos (vl-position (vla-get-TagString att) (mapcar 'cadr atts)))
	      (vla-put-TextString
		att
		(nth (vl-position
		       (nth pos (mapcar 'car atts))
		       (mapcar 'car old_lst)
		     )
		     (mapcar 'cadr old_lst)
		)
	      )
	    ) if
	  ) foreach
	)progn
      ) if   
      (vla-delete obj) 
    ) repeat
  ) if
  (setvar 'CTAB atclyt)
  (setvar 'ATTREQ old_rec)
  (princ)
);; demo

  

0 Likes
440 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Do you always have one layout per drawing? 

 

Just thinking of this...

4. Find the block name 'styklistefelt' remember its insertion point and insert the block 'Part list top'

Probably not - it needs to respect the size of BWRS_HOVED which is larger than the old one... 

0 Likes
Message 3 of 3

ВeekeeCZ
Consultant
Consultant

It's not perfect... but pretty sure you're perfectly capable of fixing it. 

 

Some things are listed wrong... as Cert for example. Did not check it all.

If you need to transfer scales and rotation as well... feel free to add them.

 

Btw. You're moving from old to new blocks.. and the move ones are 23.21548477712235... or 5.03552 in height? Really?!

 

0 Likes