extrawurscht Posted December 29, 2010 Share Posted December 29, 2010 (edited) 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 December 29, 2010 by extrawurscht icons for : Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 29, 2010 Share Posted December 29, 2010 Attached is an old one I wrote, I've quickly updated it with some new subs and it might be of help to you. The settings are all at the top of the code. Incrementing Attribute Numbering.lsp Quote Link to comment Share on other sites More sharing options...
extrawurscht Posted December 29, 2010 Author Share Posted December 29, 2010 thank you, i will try to insert in my LISP or fit yours Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 29, 2010 Share Posted December 29, 2010 Looking at your code, I should think mine is almost there already Quote Link to comment Share on other sites More sharing options...
VVA Posted December 29, 2010 Share Posted December 29, 2010 Try ti use Binc or BincA command Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.