Jump to content

insert block with attributes and set a value to a increasing number for calbe number


extrawurscht
 Share

Recommended Posts

hello,

i 'm a newbie and need help.

i need a lisp for inserting two blocks alternating for cable numbering. the first block is the start of the cable and the 2nd block is the destination. The blocks has a attribute with a value named KNUM. In this KNUM the cablenumber should get inserted. I wrote the following LISP with help of other LISPs of this forum. Is works, but at the moment i have to insert the block, and the have to select the inserted block and it changes the value KNUM to my cable Number.

Can someone help me?

for example, set the value while inserting the block,

or select a block by its insert point, so that i dont have to click a second time onto the insered block?

 

;--------------------------------------------------------------------------
; INSERTBLK
;--------------------------------------------------------------------------
(defun InsertBlock (bNme Pt)
(vl-load-com)

(vla-InsertBlock
 (if (eq acPaperSpace
   (vla-get-ActiveSpace
   (setq doc (vla-get-ActiveDocument
   (vlax-get-acad-object)))))

   (if (eq :vlax-true (vla-get-MSpace doc))
   (vla-get-ModelSpace doc)
   (vla-get-PaperSpace doc))

   (vla-get-ModelSpace doc))

(vlax-3D-point Pt) bNme 1. 1. 1. 0.)
(setvar "KNUM" bNme)
)

;--------------------------------------------------------------------------
(defun LM:SetAttributeValue ( block tag value )
 ;; © Lee Mac 2010
 (vl-some
   (function
     (lambda ( attrib )
       (if (eq tag (vla-get-TagString attrib))
         (progn (vla-put-TextString attrib value) value)
       )
     )
   )
   (vlax-invoke block 'GetAttributes)
 )
)
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
(defun c:ins (/ oldPref oldKNR curStr ss)

;(vl-load-com)

(setq snapwert (getvar "snapmode"))
(setvar "snapmode" 1)

;--------------------------------------------------------------------------
 (initget 6)
 (setq numZeros (getInt "\nAnzahl der Stellen Eingeben <4>: "))
 (if(not numZeros)(setq numZeros 4))
 
(defun num2str (num / numStr)
   (setq numStr (itoa num))
   (If (< (strlen numStr) numZeros)
     (repeat (- numZeros (strlen numStr))
   (setq numStr (strcat "0" numStr))
   )
     )
   numStr
   )
;--------------------------------------------------------------------------
;request of Prefix und Start KNR (= cable Number)
;--------------------------------------------------------------------------
(if(not rnm:Pref)(setq rnm:Pref ""))
 (setq oldPref rnm:Pref) 
(if(not rnm:KNR)(setq rnm:KNR 1))
 (setq oldKNR rnm:KNR)
(setq rnm:Pref (getstring T (strcat "\nPrefix: <"rnm:Pref">: "))) 
 (if (= "" rnm:Pref)
   (setq rnm:Pref oldPref)) 
 (if (= " " rnm:Pref)
   (setq rnm:Pref ""))
(setq rnm:KNR (getint (strcat "\nEnter Start KNR <"(itoa rnm:KNR)">: ")))
 (if (null rnm:KNR)
   (setq rnm:KNR oldKNR))
;--------------------------------------------------------------------------
(while T
(setq curStr(strcat rnm:Pref(num2Str rnm:KNR)))
;--------------------------------------------------------------------------
;Insert of Block: ZU-BUS
;--------------------------------------------------------------------------
(setq insPt (getpoint (strcat "\nInsert Point ZU <"curStr">: ")))
(InsertBlock "ZU-BUS" insPt)
;--------------------------------------------------------------------------
;set attribute in Block: ZU-BUS
;--------------------------------------------------------------------------
 (if 
(setq ss (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
   (LM:SetAttributeValue
     (vlax-ename->vla-object (ssname ss 0)) "KNUM" curStr
   )
 )


;--------------------------------------------------------------------------
;Insert of Block: VON-BUS
;--------------------------------------------------------------------------
(setq insPt (getpoint (strcat "\nInsert Point VON <"curStr">: ")))
(InsertBlock "VON-BUS" insPt)
;--------------------------------------------------------------------------
;set attribute in Block: VON-BUS
;--------------------------------------------------------------------------
 (if (setq ss (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))))
   (LM:SetAttributeValue
     (vlax-ename->vla-object (ssname ss 0)) "KNUM" curStr
   )
 )
;--------------------------------------------------------------------------
;Increasement of KNR
;--------------------------------------------------------------------------
(setq rnm:KNR(1+ rnm:KNR)) 
(princ curStr)
) ; End while
(princ)
)
;--------------------------------------------------------------------------

Edited by extrawurscht
icons for :
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
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.

 Share

×
×
  • Create New...