BrianTFC Posted December 20, 2012 Posted December 20, 2012 Hi all, I have a lisp routine that i wrote that when i run it, it will wblock out what i need to a separate file just by clicking on the border of the object, it uses the (Useri1) variable to asign the file name which is okay but i would like to be able to click on the part number (B2) for example instead so when people use it the file name is the part number. i would really appreciate any help. (defun c:psave (/ ss mn mx) (vl-load-com) (setvar "cmdecho" 0) (setvar "filedia" 0) (princ "\n Panel Number is ")(princ (getvar "useri1")) (princ ". To change this, reset the system variable USERI1") (setq pnum(getvar "useri1")) (if(= pnum 0)(setq pnum 1)) (setvar "useri1" (+ pnum 1)) (setq pnum(itoa pnum)) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn'mx) (command "wblock" pnum " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "") (setvar "cmdecho" 1) (setvar "filedia" 1) ) ) ) (princ) Thanks, Brian Quote
BrianTFC Posted December 21, 2012 Author Posted December 21, 2012 Here is a drawing of a standard panel. all i want to do is pick the (B2) for the "pnum" and then select the blue line. B2.dwg Quote
BIGAL Posted December 21, 2012 Posted December 21, 2012 Heres a way to pull out the B2 (setq text1 (entget (car (entsel "\nSelect text 1 ")))) (setq anst1 (cdr (assoc 1 text1))) then do something like (setq outdwg (strcat anst1 "-" (getvar "dwgname")) Quote
hmsilva Posted December 22, 2012 Posted December 22, 2012 perhaps something like this: (defun c:psave (/ ss mn mx sst) (vl-load-com) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn 'mx) (setq sst (ssget "W" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) '((0 . "text") (1 . "@*")) ) ) (command "-wblock" (strcat (getvar "dwgprefix") (cdr (assoc 1 (entget (ssname sst 0)))) ) " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "" ) (command "oops") ) ;; progn ) ;; if (princ) ) Quote
BrianTFC Posted December 22, 2012 Author Posted December 22, 2012 BIGAL, I did get the first lisp i wrote to do what i wanted with the following (defun c:psave2 (/ ss mn mx) (vl-load-com) ;;;--- Turn the command echo off (setvar "cmdecho" 0) ;;;--- Turn the filedia off (setvar "filedia" 0) (setq datalist (list)) ;select objects (if (setq eset (ssget)) (progn ;set a counter to the first item in the selection set (setq cntr 0) ;loop through each selected entity (while (< cntr (sslength eset)) ;grab the entity's name (setq en (ssname eset cntr)) ;grab the DXF group codes of the entity (setq enlist (entget en)) ;ignore the entity if it is not a TEXT entity (if (= "TEXT" (cdr (assoc 0 enlist))) (progn ;get the text value from the DXF Group Code (setq str (cdr (assoc 1 enlist))) ;setup a variable to check if the entity exist in the datalist list (setq existing 0) ;loop through the datalist to find out if it is a new entity that needs ;to be added to the list or if it already exist and it's counter needs ;to be incremented (foreach a datalist (if (= (car a) str) (setq existing 1) ) ) ;if the entity is new then (if (= existing 0) ;do this - Add the item to the datalist along with a counter that starts at 1 (setq datalist (append datalist (list (cons str 1)))) ;else it's cntr needs to be incremented (setq datalist (subst (cons str (+ 1 (cdr (assoc str datalist)))) (assoc str datalist) datalist ) ) ) ) ) ;increment the entity counter (setq cntr (+ cntr 1)) ) ) ) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn'mx) (command "wblock" str " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "") ;;;--- Turn the command echo back on (setvar "cmdecho" 1) ;;;--- Turn the filedia back on (setvar "filedia" 1) ) ) ) (princ) But with the lines of code that you posted it works better, with my lisp you had to hit enter in between picking the label and then the blue line. Heres my lisp with yours lines of code put together. (defun c:psave (/ ss mn mx) (vl-load-com) (setvar "cmdecho" 0) (setq text1 (entget (car (entsel "\nSelect Label ")))) (setq anst1 (cdr (assoc 1 text1))) (setq outdwg (strcat anst1 "-" (getvar "dwgname")) ) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn'mx) (command "wblock" anst1 " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "") (setvar "cmdecho" 1) ) ) ) (princ) Now you will notice i changed the "text 1" with "Label" so it doesn't confuse anyone. I was wondering what lines of code do i need to add to the lisp routine to have it save the file created to the current folder the original drawing is in. thanks for all your help BIGAL your the man. Quote
BrianTFC Posted December 22, 2012 Author Posted December 22, 2012 Hmsilva, that is exactly what i was looking for Thanks... Quote
hmsilva Posted December 22, 2012 Posted December 22, 2012 BrianTFC, if a file already exists with the same name in the current directory, the code gave an error, because the command wblock stops to ask if you want to replace the existing dwg, so I just add an "if" to see if a file already exists in the current directory with the name you want to create the wblock, if it is true, will display an alert box saying that the file already exists and exits the code. hope that helps Henrique (defun c:psave (/ ss mn mx sst) (vl-load-com) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn 'mx ) (setq sst (ssget "W" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) '((0 . "text") (1 . "@*")) ) ) (if (= (findfile (strcat (getvar "dwgprefix") (cdr (assoc 1 (entget (ssname sst 0)))) ".dwg" ) ) nil ) (progn (command "-wblock" (strcat (getvar "dwgprefix") (cdr (assoc 1 (entget (ssname sst 0)))) ) " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "" ) (command "oops") ) ;; progn (alert (strcat "\nThe " (cdr (assoc 1 (entget (ssname sst 0)))) ".dwg already exists in the current directory!!!" ) ) ) ;; if ) ;; progn ) ;; if (princ) ) Quote
pBe Posted December 23, 2012 Posted December 23, 2012 BrianTFC,if a file already exists with the same name in the current directory, the code gave an error, because the command wblock stops to ask if you want to replace the existing dwg, so I just add an "if" to see if a file already exists in the current directory with the name you want to create the wblock, if it is true, will display an alert box saying that the file already exists and exits the code. hope that helps Henrique You can set Expert to 5 to supress the message "....dwg already exists, do you want to replace it? [Yes/No] :" Nice to see you in this parts Henrique, Welcome to CADTutor. Quote
hmsilva Posted December 23, 2012 Posted December 23, 2012 Thanks pBe, I just put the alert box, in order to know that there is already a file with the same name, course if is not important to keep the file, is a good idea to set Expert to 5... Cheers Henrique Quote
BrianTFC Posted December 25, 2012 Author Posted December 25, 2012 Thanks pBe, But i like the "if" statement that Henrique put in the code, this i way i know that i can't over write any of my panels. it's a good saftey feature. Merry Christmas guys and Thank you for all the help. Quote
BrianTFC Posted December 25, 2012 Author Posted December 25, 2012 Henrique, When i ran the lisp i got the following message "; error: bad argument type: lselsetp nil". any ideas? thanks, brian Quote
hmsilva Posted December 25, 2012 Posted December 25, 2012 BrianTFC. when I tried to mechanize your code, I started from the beginning that the name of your panels began always with a letter, so in th second selection, selects text entities and filter the one that begins with a letter, "the panels name", to be the block name, and do not select the quantities, I thought they were always in brackets (1x) (2x)... The error "; error: bad argument type: lselsetp nil" is because the second selection fails "be text entity and begin with a letter", therefore can not provide a name for the new file ... Henrique Quote
BrianTFC Posted December 25, 2012 Author Posted December 25, 2012 hmsilva, You are correct, i'm a dumbbut the sample i was using to test the lisp had it panel label as an MText with (2x) instead of DText once i exploded it, it worked exactly as you said it would. Thanks so much for your help. It nice to know that i'm not the only geek sitting in front his computer on Christmas. Thanks, Brian Quote
hmsilva Posted December 25, 2012 Posted December 25, 2012 BrianTFC. now will not give this error, but it has a constraint, quantities must always be in brackets, only in this way, will be excluded from selection. (defun c:psave (/ ss mn mx sst) (vl-load-com) (if (setq ss (ssget "_:S:E" '((0 . "INSERT,LWPOLYLINE")))) (progn (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn 'mx ) (setq sst (ssget "W" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) '((0 . "text") (1 . "~(*")) ) ) (if (= (findfile (strcat (getvar "dwgprefix") (cdr (assoc 1 (entget (ssname sst 0)))) ".dwg" ) ) nil ) (progn (command "-wblock" (strcat (getvar "dwgprefix") (cdr (assoc 1 (entget (ssname sst 0)))) ) " " "0" "WINDOW" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "" ) (command "oops") ) ;; progn (alert (strcat "\nThe " (cdr (assoc 1 (entget (ssname sst 0)))) ".dwg already exists in the current directory!!!" ) ) ) ;; if ) ;; progn ) ;; if (princ) ) hope that helps Henrique Quote
BIGAL Posted December 25, 2012 Posted December 25, 2012 Add a function by www.Lee-Mac called parse.lsp it will pull the numbers out of a string this way (a2) or a-2 etc will return 2. Quote
BrianTFC Posted December 26, 2012 Author Posted December 26, 2012 Yesterday i was running the routine in Autocad 2012 and it ran great and now i'm trying to run it in Autocad 2009 and i'm getting this error message "; error: Automation Error. No database" any idea's ? Quote
hmsilva Posted December 26, 2012 Posted December 26, 2012 BrianTFC. I don't have AC09 to test the code, so, the command line type "vlide", in the "vlide" open the lisp file, on the "Debug" select "Animate", load the lisp file and return to the AC, at the command line type psave and see where the error the code gives, then post where it gives error and the error... I think it is something with "activex", but I'm not sure. Henrique Quote
BrianTFC Posted December 26, 2012 Author Posted December 26, 2012 this where it stops in vlide, (ssname ss 0). same error as before. Quote
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.