patjeacad Posted April 24 Share Posted April 24 hello everyone, what I would like to program in lisp is the following: in the drawing I have a block (bolt) of which I want to use the name to enter another block (nut). I test for insert 0 and test for the name of the block. Because there are many lengths of, for example, an M8 bolt, the name of the block must be filtered, otherwise the correct block (nut) will not be automatically selected and placed in the drawing. see attached lisp file, with comments. (DEFUN c:nutinsert (/ A B D ) (PROGN (SETQ A (ENTSEL "\nSelect Block: ")) (IF A (PROGN ; (SETQ B (CDR (ASSOC 0 (ENTGET (CAR A))))) (IF (NOT (= B "INSERT")) (ALERT "\nselectinset is not a Block.") ) (IF (= B "INSERT") (PROGN (SETQ D (CDR (ASSOC 2 (ENTGET (CAR A))))) ;get blockname ;following are examples of bolt names, the list is much longer. I only need (IF (OR (= D "NEN1555-M08x070E") ;M8 (OR (= D "NEN1555-M06x040E")) ;M6 (OR (= D "NEN1555-M10x090E")) ;M10 (OR (= D "NEN1555-M16x100E")) ;M16 (OR (= D "NEN1568-M03x050E")) ;M3 (OR (= D "NEN1568-M08x120E")) ;M8 (OR (= D "NEN1568-M06x060E")) ;M6 (= D "NEN1555-M12x050E")) ;M12 ;I need a filter only M8 OR M6 OR M10 ECT, of the blockname. (PROGN (Setvar "Cmdecho" 0) (SETQ OLDLAYER (GETVAR "CLAYER")) (SETQ LAY (IF (NOT (TBLSEARCH "LAYER" "03_GEOMETRIE_050")) (COMMAND "LAYER" "M" "03_GEOMETRIE_050" "C" "7" "" "L" "CONTINUOUS" "" "")) ) (COMMAND "LAYER" "S" "03_GEOMETRIE_050" "") (SETQ Y (getpoint "\nGeef Invoegpunt : ")) (Command "-Insert" "NEN1560-M008-E";the BLOCK name is based on M8. ;it has to be flexible, M3 M4 M5 M6 M8 M10 ECT. Y "" "" Pause) (SETVAR "CLAYER" OLDLAYER) (PRINC) ) ) ) ) ) ) ) ) (PRINC) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 24 Share Posted April 24 A couple of different ways find the "-" using (vl-position then look at each character after it should be a "M" Then a "0 1 2 3 4 5 6 7 8 9" then check next if its also "0 1 2 3 4 5 6 7 8 9" Try this (setq str "NEN1555-M06x040E") (setq pos (+ 2 (vl-string-position 45 str))) (setq char1 (strcase (substr str pos 1))) (if (/= char1 "M") (princ "\nThe text chosen does not have a M bolt ") (progn (setq char2 (substr str (+ 1 pos) 1)) (if (or (< (ascii char2) 58)(> (ascii char2) 47)) (setq str2 (strcat char1 char2)) ) (setq char2 (substr str (+ 2 pos) 1)) (if (or (< (ascii char2) 58)(> (ascii char2) 47)) (setq str2 (strcat str2 char2)) ) ) ) ; "M06" Quote Link to comment Share on other sites More sharing options...
patjeacad Posted May 15 Author Share Posted May 15 (edited) hi to all users, I got a solution from BIGAL and it is a nice solution. Only the (if (/= char1 "M") does not work. perhaps i made a mistake in my lisp routine. Can someone help me with this. (Defun c:DIN934 (/ FORMAAT) (SETQ FORMAAT (SSGET "X" (list (cons 8 "BL$2----_KADER")))) (IF (NOT FORMAAT)(ALERT "\n Kan Commando niet uitvoeren. Geen Kader aanwezig !!! ")) (IF FORMAAT (PROGN (DIN934A))) (PRINC) ) (defun DIN934A(/ A B str pos char1 char2 str2) (initget "Automatisch Handmatig ") (setq ans (cond ((getkword "\nMoer plaatsen [Automatisch/Handmatig] <Automatisch>: ")) ("Automatisch"))) (if (= ans "Handmatig")(DIN934handmatig)) (if (= ans "Automatisch") ;SLeutelwijdte (PROGN (SETQ A (ENTSEL "\nSelecteer Bout: ")) (IF A (PROGN ;automatische selectie moer (SETQ B (CDR (ASSOC 0 (ENTGET (CAR A))))) (IF (NOT (= B "INSERT")) (ALERT "\nGeselecteerde is geen Block. Start opnieuw") ) (IF (= B "INSERT") (PROGN (setq str (CDR (ASSOC 2 (ENTGET (CAR A))))) ;get blockname (setq pos (+ 2 (vl-string-position 45 str))) (setq char1 (strcase (substr str pos 1))) (if (/= char1 "M") ;Does not work if wrong block selected error: bad argument type: numberp: nil (princ "\nGekozen Block is geen Bout ") (progn (setq char2 (substr str (+ 1 pos) 1)) (if (or (< (ascii char2) 58)(> (ascii char2) 47)) (setq str2 (strcat char1 char2)) ) (setq char2 (substr str (+ 2 pos) 1)) (if (or (< (ascii char2) 58)(> (ascii char2) 47)) (setq str2 (strcat str2 char2)) ;value str2 M04, M05, M06, M12 ect. ) ) ) (PROGN (COND ((= str2 "M04")(setq sstr2 "DIN934-M004-E")) ((= str2 "M05")(setq sstr2 "DIN934-M005-E")) ((= str2 "M06")(setq sstr2 "DIN934-M006-E")) ((= str2 "M07")(setq sstr2 "DIN934-M007-E")) ((= str2 "M08")(setq sstr2 "DIN934-M008-E")) ((= str2 "M10")(setq sstr2 "DIN934-M010-E")) ((= str2 "M12")(setq sstr2 "DIN934-M012-E")) ((= str2 "M14")(setq sstr2 "DIN934-M014-E")) ((= str2 "M16")(setq sstr2 "DIN934-M016-E")) ) ) (PROGN (Setvar "Cmdecho" 0) (setq osm (getvar "osmode")) (Setvar "osmode" 545) (SETQ OLDLAYER (GETVAR "CLAYER")) (SETQ LAY (IF (NOT (TBLSEARCH "LAYER" "03_GEOMETRIE_050")) (COMMAND "LAYER" "M" "03_GEOMETRIE_050" "C" "7" "" "L" "CONTINUOUS" "" "")) ) (COMMAND "LAYER" "S" "03_GEOMETRIE_050" "") (SETQ Y (getpoint "\nGeef Invoegpunt : ")) (Command "-Insert" sstr2 Y "" "" Pause) (SETVAR "CLAYER" OLDLAYER) (setvar "osmode" osm) ) ) ) (PRINC) ) ) ) ) ) (PRINC) Edited May 15 by SLW210 Added Code Tags! Quote Link to comment Share on other sites More sharing options...
SLW210 Posted May 15 Share Posted May 15 Please use Code Tags! (<> in editor toolbar) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 15 Share Posted May 15 A maybe approach so exits if not a block slected. (IF (NOT (= B "INSERT")) (ALERT "\nGeselecteerde is geen Block. Start opnieuw") ) (IF (= B "INSERT") (PROGN (IF (= B "INSERT")) (progn do B = Insert ) ; progn b= insert (progn (ALERT "\nGeselecteerde is geen Block. Start opnieuw \n\nWill now exit")(exit)) ) ; end of b= insert IF Quote Link to comment Share on other sites More sharing options...
mhupp Posted May 16 Share Posted May 16 (edited) If your only using a set number of defined blocks I suggest making two list BLst for the bolts and NLst for the corresponding nuts. make sure each list has a matching partner. if the M16 bolt is position 5 make the nut that goes with that bolt is in position 5 in the nut list. Then using vl-postion you can test for the block name & get the position in the list. storing the position number and after switching to the layer & getting the insert point you can call the insert command using the (nth pos NLst) to call the correct nut block by name. Need to update a few things for this to work create the NLst names & the path to where all these blocks are (2nd insert command) Made a few updates to the code use while instead of if so it will keep running if you keep selecting an entity. Will tell the lisp to run itself again if a block isn't selected. dont select anything to exit the command Used entmake to make the layer so you don't have to turn off cmdecho. non is needed in the insert command or could snap to another entity close to point picked. test if block is already in the drawing insert and inserts if yes inserts from path if not. --edit I see there is two m6 and two m8 if these use the same nut block just add it twice into the NLst so their in the same position. Nutinsert.lsp Edited May 16 by mhupp Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 16 Share Posted May 16 Have a look at this not sure where I got it. Has a nut already. DYNAMIC BOLT.dwg Quote Link to comment Share on other sites More sharing options...
Steven P Posted May 16 Share Posted May 16 For nuts and bolts - I have never measured this but isn't say an M12 nut twice the size of M6? So you only need 1 nut and scaled to suit, you'd still need different bolts due to the thread length. Quote Link to comment Share on other sites More sharing options...
patjeacad Posted May 16 Author Share Posted May 16 thanks all for your input. for Mhupp; i can't make a bolt list. that list would be to long. There are several type of bolts; m4 m5 m6 ect. There is also a different lenght. Thats why i need a small code from the bolt blockname to insert the correct nut. The bolt is already in the drawing, select the bolt and the correct nut has to be inserted. I also want to use this routine for washers. thanks for your input. 22 hours ago, SLW210 said: Please use Code Tags! (<> in editor toolbar) Quote Link to comment Share on other sites More sharing options...
patjeacad Posted May 16 Author Share Posted May 16 Hi Steven, your solution is posible. if i use different bolts they have there own name. if i scale a block they have the same name. moost of the time you need a correct count of bolts in a drawing. 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 16 Share Posted May 16 (edited) Did you look at the Bolt I posted has different sizes includes a nut and can be stretched that is what a Dynamic block is about much easier than lisp to use. Steven P yes there are rules about Bolt head/nut sizes that are relevant to bolt size, for end elevations there are 2 views as you can view across flats or with edge facing which is lightly wider. Look at a hexagon polygon. If I remember correct G is 2xDia. Edited May 17 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted May 17 Share Posted May 17 Bolts come in standard lengths unless you are custom making them. I just have a set of blocks for each bolt length for each type and size (really not a lot of different ones I use so not a huge amount), each block has a different name so easy to count them. (I plan to make some dynamic blocks eventually) Nuts are separate and so are washers, so I get a count on those as well. Lot's of LISPs etc. around to create a list (BOM) for block names. Easy to do the same with a dynamic block with Visibility States, etc. to get a count. Just for a start... Dynamic Block Counter | Lee Mac Programming (lee-mac.com) Dynamic Block Functions | Lee Mac Programming (lee-mac.com) Maybe have an attribute added with information? Connecting attribute values to visibility states for dynamic blocks in AutoCAD (autodesk.com) Quote Link to comment Share on other sites More sharing options...
patjeacad Posted May 17 Author Share Posted May 17 thank you Bigal and SLW201. I have already all the blocks of bolts and nuts. And i want to use Lisp. You helped me all. I saw the block counter of Lee Mac. is't a perfect routine. Very Nice program. I'v been helped greatly en thanks all. regards PatjeCad. 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.