au-s Posted October 29, 2010 Share Posted October 29, 2010 Hi, I am trying to accomplish this: If I choose a file matching P*-1.dwg it will take that file, xref it into the sheet and then insert the block called STAMP_1 depending on what condition is made. fname is the file I choose PNAMN-1.dwg or PNAMN-2.dwg or PNAMN-3.dwg (defun c:test ( / fname) (INSERT1) (if fname (cond (wcmatch fname "P*-1*")(STAMP_1) (wcmatch fname "P*-2*")(STAMP_2) )) );defun The INSERT1 works and it's xfreffs in a chosen file PNAMN-1.dwg or PNAMN-2.dwg or PNAMN-3.dwg. Now I have blocks that I want to insert but depending on what PNAMN-* I choose the correct STAMP_1/STAMP_2/STAMP-3 is inserted. The STAMP_1 and STAMP_2 works as well and inserts the block withj 0,0,0 and exaclty how I want it. So, what is wrong with wcmatch? Do I miss something. Newbie here. Thankls for all help. I also teried with : (defun c:test ( / fname) (INSERT1) (if fname (cond ((wcmatch fname "P*-1*") T) (STAMP_1) ((wcmatch fname "P*-2*") T) (STAMP_2) )) );defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 29, 2010 Share Posted October 29, 2010 (defun c:test ( / fname ) (INSERT1) (if fname (cond ( (wcmatch fname "P*-1*") (STAMP_1) ) ( (wcmatch fname "P*-2*") (STAMP_2) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 Returns NIL after the xref has been inserted. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 29, 2010 Share Posted October 29, 2010 Returns NIL after the xref has been inserted. You might need to add (princ) at the end of routine to exit calmly. Tharwat Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 Tharwat , It returns nil and doesn't insert the block but it xrefs in the dwg. So the INSERT1 is okay but STAMP_1 or STAMP_2 doesn't. But when I do those functions seperatly, they do work. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 29, 2010 Share Posted October 29, 2010 So can you post your codes that are related to the (INSERT1) ? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 29, 2010 Share Posted October 29, 2010 Returns NIL after the xref has been inserted. Have you tested the wcmatch condition on a sample filename? Are the filenames in upper case? (defun c:test ( / fname ) (INSERT1) (if fname (cond ( (wcmatch fname "P*-1*") (STAMP_1) ) ( (wcmatch fname "P*-2*") (STAMP_2) ) (t (alert "No Conditions Met") ) ) ) ) Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 (Defun checkxref () (if (tblsearch "layer" "P-------XREF") (command "_layer" "s" "P-------XREF" "") (command "_layer" "m" "P-------XREF" "c" "7" "" "lo" "P-------XREF" "" ) ) ) (defun STAMP_1 (/ stamp1 oldlay ) (initerr) (progn (setq stamp1 (strcat "..\\..\\KOMP_FIL\\Stämpel\\STAMP\\_STAMP-1.dwg")) ;(checkxref) (setq point0 (strcat "0,0,0")) (command "-insert" stamp1 point0 "1" "1" "0" "" "" "" "" "" "" "" "" "" "") ) ) (defun STAMP_2 (/ stamp2 oldlay ) (initerr) (progn (setq stamp2 (strcat "..\\..\\KOMP_FIL\\Stämpel\\STAMP\\_STAMP-2.dwg")) ;(checkxref) (setq point0 (strcat "0,0,0")) (command "-insert" stamp2 point0 "1" "1" "0" "" "" "" "" "" "" "" "" "" "") ) ) ;;; CODE ORIGINALLY WRITTEN BY Lee_Mac, Thank you (defun INSERT1 (/ laycode lay_name fname oldlay path test) ;laycodes is a list of a drawing paths, layer names and preset colors. ;Each list within laycodes contains 3 elements (<path> <layer name> <layer color>) ;The first element is the block path. ;The second element is the layer name associated with the block ;The third item in a list references the layer color ;Any blocks found to come from a particular path will be inserted on a preset layer ;If the layer does not exist it will be created and a layer color assigned to it ; ;eg ;("K:\\CAD\\Block\\arrow" "A-------O2-" 1) ;A block inserted from "K:\\CAD\\Block\\arrow" will be inserted on layer "A-------O2-" which has a color 1 ; ;Note the path is case sensitive ;(NAMNRUTA) (command "_.layer" "s" 0 "") (setq laycodesrelativepath (dos_relativepath "U:\\?\\?\\A\\Ritningar\\RITDEF\\?" "U:\\?\\?\\A\\Ritningar\\KOMP_FIL\\Stämpel" )) (setq point0 (strcat "0,0,0")) (setq laycodes '( ("U:\\p-q-r\\RF_TEST_AU\\A\\Ritningar\\KOMP_FIL\\Stämpel" "A-------F1-" 4) ;<-edit this list as required ) ) (setq stamppath (dos_relativepath "U:\\?\\?\\A\\Ritningar\\RITDEF\\?" "U:\\?\\?\\A\\Ritningar\\KOMP_FIL\\Stämpel" )) (IF (= (getvar "tilemode") 0) (progn (if ;select the drawing to insert (and (setq fname (dos_dwgpreview "Välj NAMNRUTA:" stamppath ".dwg")) (/= fname "")) ;if a file has been selected (progn ;store the current layer (setq oldlay (getvar "clayer")) ;retrieve the path (setq path (vl-filename-directory fname)) (if ;check the path against the laycodes (setq test (assoc path laycodes)) ;if a match is found (or ;test if the preset layer exists (tblsearch "layer" (setq lay_name (cadr test))) ;if it does not add it (and (command "layer" "m" lay_name "c" (caddr test) lay_name "") ;<-line added to change the layer to the required color ) ) ;if the file does not match the predefined (alert (strcat "\n<" (vl-filename-base fname) "> är EJ vald från GILTIG katalog" " \nGiltiga Kataloger är :" (apply 'strcat (mapcar '(lambda (x) (strcat "\n\t" (car x))) laycodes)) "\nBlock <" (vl-filename-base fname) "> skall vara infogad i lager <" (getvar "clayer")">"))) (and lay_name (setvar "clayer" lay_name)) (setvar "cmdecho" 0) (command "_.xref" "o" fname "0,0" "" "" "" ) (and lay_name (setvar "clayer" oldlay)) ) (alert "\nIngen fil vald...") ) (princ))(alert "Infoga Skalsymbol i RitDef:ar istället!!")) (C:XR:RelativePath) ) ;;; (defun c:test ( / svar fname) ;;;(setq flag (dos_msgbox "Spara på Rätt ställe. Om Sparat, tryck JA/YES, om ej Spara och kör igen!" 4 3)) ;;; ;display the message box ;;; ;;; ;;; (if (= flag 6) ;;; ;if Yes selected ;;; (progn ;;; (initdia) ;;;(if (/= (getvar "ctab") "Model") ;;; (progn ;;; (setq ;;; svar (dos_msgbox ;;;"SPARA på RÄTT STÄLLE. Om sparat VÄLJ JA, annars nej och SPARA på rätt ställe och KÖR IGEN!)" ;;; "SÄTT IN STÄMPEL!" ;;; 4 ;;; 3 ;;; ) ;;; ) ;;; (IF (= svar 6) ;;; (progn (INSERT1) (if fname (cond ( (wcmatch fname "PNAMN*1*") (STAMP_1) ) ( (wcmatch fname "PNAMN*2*") (STAMP_2) ) ) )) ) (princ) ;;; (initdia) ;;; (command "_.save") Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 29, 2010 Share Posted October 29, 2010 Please use the (code-tag) Thanks Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 I think I resolved it (defun c:test () (INSERT1) (if (ssget "x" '((2 . "PNAMN-?"))) (progn (if ( (wcmatch fname "PNAMN*1*") (STAMP_2) ) ( (wcmatch fname "PNAMN*2*") (STAMP_2) ) ) ) )) (princ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 29, 2010 Share Posted October 29, 2010 I think I resolved it (defun c:test () (INSERT1) (if (ssget "x" '((2 . "PNAMN-?"))) (progn (if ( (wcmatch fname "PNAMN*1*") (STAMP_2) ) ( (wcmatch fname "PNAMN*2*") (STAMP_2) ) ) ))) (princ) Congratulations for the first one . The following codes need some corrections , (setq stamp1 [b][color="red"](strcat[/color][/b] "..\\..\\KOMP_FIL\\Stämpel\\STAMP\\_STAMP-1.dwg")) [color="red"][b](setq point0 (strcat "0,0,0"))[/b][/color] (command "-insert" stamp2 point0 "1" "1" "0" "" "" "" "" "" "" "" "" "" "") ) ) There is no need for function (strcat) for the above codes , (setq stamp1 "..\\..\\KOMP_FIL\\Stämpel\\STAMP\\_STAMP-1.dwg") (command "-insert" stamp2 [b][color="red"]"0,0,0"[/color][/b] "1" "1" "0" "" "" "" "" "" "" "" "" "" "") ) ) Regards, Tharwat Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 hmm... Seems STAMP_2 doesnt insert... It inserts the block from STAMP_1 anyway Quote Link to comment Share on other sites More sharing options...
au-s Posted October 29, 2010 Author Share Posted October 29, 2010 BUT that seems to work okay. (defun test () (INSERT1) (if (ssget "x" '((2 . "PNAMN-?"))) (progn (cond ( (ssget "x" '((2 . "PNAMN-1"))) (STAMP_1) ) ( (ssget "x" '((2 . "PNAMN-2"))) (STAMP_2) ) ) ;if ) ;progn ) ;if ) ;defun (princ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 29, 2010 Share Posted October 29, 2010 BUTthat seems to work okay. (defun test () (INSERT1) (if (ssget "x" '((2 . "PNAMN-?"))) (progn (cond ( (ssget "x" '((2 . "PNAMN-1"))) (STAMP_1) ) ( (ssget "x" '((2 . "PNAMN-2"))) (STAMP_2) ) ) ;if ) ;progn ) ;if ) ;defun (princ) If you are going that route, there's no need to check the initial selection set. eg. (defun test (/) (INSERT1) (cond ((ssget "_X" '((2 . "PNAMN-1"))) (STAMP_1)) ((ssget "_X" '((2 . "PNAMN-2"))) (STAMP_2)) ) ) 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.