Jump to content

Recommended Posts

Posted (edited)

Hello the Community,

I am trying to combine two lisp into one , without sucess..

 The first lisp is for deleting  all atributes from selected blocks

The second is to add liste of attributes to them  ( little problem on this, I can't manage to define the attributes alignment to center )

I am trying to combine them into 1 lisp

Could some one help me to fix it

Thank You in advance for your help

Cheers.

Dany

The 1st Lisp


(defun tl_fld (v1 v2) (cdr (assoc v1 v2)))

(defun c:attdel2 (/	     ss		cnt	   blk
		  blkdat     blknam	blktblnam  blknewdat 
		  blktbldat  newblkdat	atk_dbug   nextent
		  nextentdat nextenttyp	endblklst
		 )
  (command "undo" "group")
  (setq atk_dbug nil)
  ;;  (setq atk_dbug T)
  (if (setq ss (ssget (list (cons 0 "insert") (cons 66 1))))
    (progn
      (setq cnt -1)
      (repeat (sslength ss)
	(setq blk	(ssname ss (setq cnt (1+ cnt)))
	      blkdat	(entget blk)
	      blknam	(tl_fld 2 blkdat)
	      newblknam	(strcat blknam "_na")
	      blknewdat	(subst (cons 2 newblknam)
			       (assoc 2 blkdat)
			       blkdat
			)
	      blknewdat	(subst (cons 66 0)
			       (assoc 66 blknewdat)
			       blknewdat
			)
	)
	(if (not (tblsearch "block" newblknam))
	  (progn
	    (setq blktblnam (tblobjname "block" blknam)
		  blktbldat (entget blktblnam)
		  newblkdat (subst (cons 2 newblknam)
				   (assoc 2 blktbldat)
				   blktbldat
			    )
		  newblkdat (subst (cons 70 (- (tl_fld 70 blktbldat) 2))
				   (assoc 70 blktbldat)
				   newblkdat
			    )
	    )
	    (if	(entmake newblkdat)
	      (progn
		(if atk_dbug
		  (princ "\nStarting new block definition . . . ")
		)
		(setq nextent	 (entnext blktblnam)
		      nextentdat (entget nextent)
		      nextenttyp (tl_fld 0 nextentdat)
		)
		(while (and nextenttyp (/= nextenttyp "ENDBLK"))
		  (if (/= nextenttyp "ATTDEF")
		    (if	(not (entmake nextentdat))
		      (princ "\nCan't make subentity.")
		      (if atk_dbug
			(princ (strcat "\nAdding "
				       nextenttyp
				       " as subentity "
				       (itoa xcnt)
			       )
			)
		      )
		    )
		    (if	atk_dbug
		      (princ "\nSkipping attribute definition.")
		    )
		  )
		  (setq	nextentdat
				   nil
			nextenttyp nil
		  )
		  (if (setq nextent (entnext nextent))
		    (setq
		      nextentdat (entget nextent)
		      nextenttyp (tl_fld 0 nextentdat)
		    )
		  )
		)
		(setq endblklst	(list (cons 0 "endblk")
				      (cons 100 "AcDbBlockEnd")
				)
		)
		(if (not (entmake endblklst))
		  (princ "\nCan't terminate block definition")
		)
	      )
	      (princ "\nCan't start new block definition.")
	    )
	  )
	)
	(if (tblsearch "block" newblknam)
	  (progn
	    (entdel blk)
	    (entmake blknewdat)
	  )
	)

      )
      (setq ss nil)
    )
  )
  (command "undo" "end")
  (tl_$tlp)
)

The second:  Missing the alignmentCenter Attributes

(defun c:addatribs ( / ss i blk blks def )
    (and
       (setq ss (ssget '((0 . "INSERT"))))
       (setq i (sslength ss))
       (while (> i 0)
          (setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))))
          (if (not (vl-position blk blks))(setq blks (cons blk blks)))
       )
    )
    (foreach blk blks
         (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk))
	(vla-addattribute def
;------------ATTRIBUT 01 ---------------------------------------------------    
		3
             acattributemodelockposition
             "DENOMBREMENT"
             (vlax-3D-point 0 +9)
		;(vlax-put def 'Alignment 4)
		;(vlax-put def acAlignmentmiddle) 
	
             "DENOMBREMENT"
             "xxxx"
         )
;------------ATTRIBUT 02 ---------------------------------------------------  
         (vla-addattribute def
             
		3
             acattributemodelockposition
             "TYPE/CLASSE"
             (vlax-3D-point 0 +5)
             "TYPE/CLASSE"
             "xxxx"
         )
;------------ATTRIBUT 03 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#2"
             (vlax-3D-point 0 -7)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#2"
             "xxxx"
         )
;------------ATTRIBUT 04 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#3"
             (vlax-3D-point 0 -11)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#3"
             "xxxx"
         )

;------------ATTRIBUT 05 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#4"
             (vlax-3D-point 0 -15)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#4"
             "xxxx"
         )

;------------ATTRIBUT 06 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#5"
             (vlax-3D-point 0 -19)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#5"
             "xxxx"
         )

;------------ATTRIBUT 07 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DESIGNATION_ZONE"
             (vlax-3D-point 0 -23)
             "DESIGNATION_ZONE"
             "xxxx"
         )


;------------ATTRIBUT 08 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "COSWIN"
             (vlax-3D-point 0 -27)
             "COSWIN"
             "xxxx"
         )
;------------ATTRIBUT 09 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "NUM_LOCAL"
             (vlax-3D-point 0 -31)
             "NUM_LOCAL"
             "xxxx"
         )
;------------ATTRIBUT 10 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "POSITION_BORDEREAU"
             (vlax-3D-point 0 -31)
             "POSITION_BORDEREAU"
             "xxxx"
         )

;------------ATTRIBUT 11 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DENOMINATION"
             (vlax-3D-point 0 -35)
             "DENOMINATION"
             "xxxx"
         )

;------------ATTRIBUT 12 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "FOURNISSEUR"
             (vlax-3D-point 0 -39)
             "FOURNISSEUR"
             "xxxx"
         )
;------------ATTRIBUT 13 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "MARQUE"
             (vlax-3D-point 0 -43)
             "MARQUE"
             "xxxx"
         )
;------------ATTRIBUT 14 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "N°_DE_SERIE/REF"
             (vlax-3D-point 0 -47)
             "N°_DE_SERIE/REF"
             "xxxx"
         )
;------------ATTRIBUT 15 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ANNEE_DE_FABRICATION"
             (vlax-3D-point 0 -51)
             "ANNEE_DE_FABRICATION"
             "xxxx"
         )
;------------ATTRIBUT 16 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DEBUT_DE_GARANTIE"
             (vlax-3D-point 0 -51)
             "DEBUT_DE_GARANTIE"
             "xxxx"
         )
;------------ATTRIBUT 17 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DUREE_DE_GARANTIE"
             (vlax-3D-point 0 -55)
             "DUREE_DE_GARANTIE"
             "xxxx"
         )
;------------ATTRIBUT 18 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "REF_FICHE_TECHNIQUE"
             (vlax-3D-point 0 -59)
             "REF_FICHE_TECHNIQUE"
             "xxxx"
         )
;------------ATTRIBUT 19 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_1"
             (vlax-3D-point 0 -63)
             "ATTRIBUT_1"
             "xxxx"
         )
;------------ATTRIBUT 20 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_2"
             (vlax-3D-point 0 -67)
             "ATTRIBUT_2"
             "xxxx"
         )
;------------ATTRIBUT 21 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_3"
             (vlax-3D-point 0 -71)
             "ATTRIBUT_3"
             "xxxx"
         )


	;(vlax-put 'Alignment acAlignmentmiddle) ;; 4
         (command "_.attsync" "_N" blk)
     )
    (princ)
)
(vl-load-com) (princ)

And there is a try to combien them:  ( missing a line for attributes synchronisation)


(defun tl_fld (v1 v2) (cdr (assoc v1 v2)))

(defun c:kad (/	     ss		cnt	   blk
		  blkdat     blknam	blktblnam  blknewdat 
		  blktbldat  newblkdat	atk_dbug   nextent
		  nextentdat nextenttyp	endblklst
		 )
  (command "undo" "group")
  (setq atk_dbug nil)
  ;;  (setq atk_dbug T)
  (if (setq ss (ssget (list (cons 0 "insert") (cons 66 1))))
    (progn
      (setq cnt -1)
      (repeat (sslength ss)
	(setq blk	(ssname ss (setq cnt (1+ cnt)))
	      blkdat	(entget blk)
	      blknam	(tl_fld 2 blkdat)
	      newblknam	(strcat blknam "_na")
	      blknewdat	(subst (cons 2 newblknam)
			       (assoc 2 blkdat)
			       blkdat
			)
	      blknewdat	(subst (cons 66 0)
			       (assoc 66 blknewdat)
			       blknewdat
			)
	)
	(if (not (tblsearch "block" newblknam))
	  (progn
	    (setq blktblnam (tblobjname "block" blknam)
		  blktbldat (entget blktblnam)
		  newblkdat (subst (cons 2 newblknam)
				   (assoc 2 blktbldat)
				   blktbldat
			    )
		  newblkdat (subst (cons 70 (- (tl_fld 70 blktbldat) 2))
				   (assoc 70 blktbldat)
				   newblkdat
			    )
	    )
	    (if	(entmake newblkdat)
	      (progn
		(if atk_dbug
		  (princ "\nStarting new block definition . . . ")
		)
		(setq nextent	 (entnext blktblnam)
		      nextentdat (entget nextent)
		      nextenttyp (tl_fld 0 nextentdat)
		)
		(while (and nextenttyp (/= nextenttyp "ENDBLK"))
		  (if (/= nextenttyp "ATTDEF")
		    (if	(not (entmake nextentdat))
		      (princ "\nCan't make subentity.")
		      (if atk_dbug
			(princ (strcat "\nAdding "
				       nextenttyp
				       " as subentity "
				       (itoa xcnt)
			       )
			)
		      )
		    )
		    (if	atk_dbug
		      (princ "\nSkipping attribute definition.")
		    )
		  )
		  (setq	nextentdat
				   nil
			nextenttyp nil
		  )
		  (if (setq nextent (entnext nextent))
		    (setq
		      nextentdat (entget nextent)
		      nextenttyp (tl_fld 0 nextentdat)
		    )
		  )
		)
		(setq endblklst	(list (cons 0 "endblk")
				      (cons 100 "AcDbBlockEnd")
				)
		)
		(if (not (entmake endblklst))
		  (princ "\nCan't terminate block definition")
		)
	      )
	      (princ "\nCan't start new block definition.")
	    )
	  )
	)
	(if (tblsearch "block" newblknam)
	  (progn
	    (entdel blk)
	    (entmake blknewdat)
	  )
	)

      )
      (setq ss nil)
    )
  )
  (command "undo" "end")
  (tl_$tlp)
;(princ)
)
;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(defun c:addatribs ( / ss i blk blks def )
    (and
       (setq ss (ssget '((0 . "INSERT"))))
       (setq i (sslength ss))
       (while (> i 0)
          (setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))))
          (;if (not (vl-position blk blks))(setq blks (cons blk blks)))
       )
    )
    (foreach blk blks
         (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk))
	(vla-addattribute def
;------------ATTRIBUT 01 ---------------------------------------------------    
		3
             acattributemodelockposition
             "DENOMBREMENT"
             (vlax-3D-point 0 +9)
		;(vlax-put def 'Alignment 4)
		;(vlax-put def acAlignmentmiddle) 
	
             "DENOMBREMENT"
             "xxxx"
         )
;------------ATTRIBUT 02 ---------------------------------------------------  
         (vla-addattribute def
             
		3
             acattributemodelockposition
             "TYPE/CLASSE"
             (vlax-3D-point 0 +5)
             "TYPE/CLASSE"
             "xxxx"
         )
;------------ATTRIBUT 03 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#2"
             (vlax-3D-point 0 -7)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#2"
             "xxxx"
         )
;------------ATTRIBUT 04 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#3"
             (vlax-3D-point 0 -11)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#3"
             "xxxx"
         )

;------------ATTRIBUT 05 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#4"
             (vlax-3D-point 0 -15)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#4"
             "xxxx"
         )

;------------ATTRIBUT 06 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodelockposition
             "CIRCUIT_ELEC/ADR_KNX/DALI_#5"
             (vlax-3D-point 0 -19)
             "CIRCUIT_ELEC/ADR_KNX/DALI_#5"
             "xxxx"
         )

;------------ATTRIBUT 07 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DESIGNATION_ZONE"
             (vlax-3D-point 0 -23)
             "DESIGNATION_ZONE"
             "xxxx"
         )


;------------ATTRIBUT 08 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "COSWIN"
             (vlax-3D-point 0 -27)
             "COSWIN"
             "xxxx"
         )
;------------ATTRIBUT 09 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "NUM_LOCAL"
             (vlax-3D-point 0 -31)
             "NUM_LOCAL"
             "xxxx"
         )
;------------ATTRIBUT 10 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "POSITION_BORDEREAU"
             (vlax-3D-point 0 -31)
             "POSITION_BORDEREAU"
             "xxxx"
         )

;------------ATTRIBUT 11 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DENOMINATION"
             (vlax-3D-point 0 -35)
             "DENOMINATION"
             "xxxx"
         )

;------------ATTRIBUT 12 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "FOURNISSEUR"
             (vlax-3D-point 0 -39)
             "FOURNISSEUR"
             "xxxx"
         )
;------------ATTRIBUT 13 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "MARQUE"
             (vlax-3D-point 0 -43)
             "MARQUE"
             "xxxx"
         )
;------------ATTRIBUT 14 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "N°_DE_SERIE/REF"
             (vlax-3D-point 0 -47)
             "N°_DE_SERIE/REF"
             "xxxx"
         )
;------------ATTRIBUT 15 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ANNEE_DE_FABRICATION"
             (vlax-3D-point 0 -51)
             "ANNEE_DE_FABRICATION"
             "xxxx"
         )
;------------ATTRIBUT 16 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DEBUT_DE_GARANTIE"
             (vlax-3D-point 0 -51)
             "DEBUT_DE_GARANTIE"
             "xxxx"
         )
;------------ATTRIBUT 17 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "DUREE_DE_GARANTIE"
             (vlax-3D-point 0 -55)
             "DUREE_DE_GARANTIE"
             "xxxx"
         )
;------------ATTRIBUT 18 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "REF_FICHE_TECHNIQUE"
             (vlax-3D-point 0 -59)
             "REF_FICHE_TECHNIQUE"
             "xxxx"
         )
;------------ATTRIBUT 19 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_1"
             (vlax-3D-point 0 -63)
             "ATTRIBUT_1"
             "xxxx"
         )
;------------ATTRIBUT 20 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_2"
             (vlax-3D-point 0 -67)
             "ATTRIBUT_2"
             "xxxx"
         )
;------------ATTRIBUT 21 ---------------------------------------------------  
		(vla-addattribute def
             
		3
             acattributemodeinvisible
             "ATTRIBUT_3"
             (vlax-3D-point 0 -71)
             "ATTRIBUT_3"
             "xxxx"
         )


	;(vlax-put 'Alignment acAlignmentmiddle) ;; 4
         (command "_.attsync" "_N" blk)
     )
    (princ)
)
(vl-load-com) (princ)




 (DEFUN C:NEWCOMMAND;
(C:kad)
(C:addatribs)
(princ)
)

 

Edited by Dany Jee
Posted

Hello Bigal,

Sorry but burst is not what I'am expecting to do..

My two lisp are doing it well ( excep for the alignement which I don't know how to write the command) but separately, and I'am looking for combien them in only one lisp

 

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