CadFrank Posted March 2, 2016 Posted March 2, 2016 Hi, I'm trying to create a block and well i'm not sure why it doesn't work. Could someone help me out or guide me. (defun CreationBois (Nom Dim1 Dim2) (entmake (list '(0 . "BLOCK") (cons 2 nom) (cons 10 (list (/ Dim1 2) Dim2)) '(70 . 1) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") '(10 0 0) (cons 11 (list Dim1 0)) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") (cons 10 (list Dim1 0)) (cons 11 (list Dim1 Dim2)) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") (cons 10 (list Dim1 Dim2)) (cons 11 (list 0 Dim2)) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") (cons 10 (list 0 Dim1)) '(11 0 0) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") '(10 0 0) (cons 11 (list Dim1 Dim2)) ) ) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") (cons 10 (list Dim1 0)) (cons 11 (list 0 Dim2)) ) ) (entmake (list '(0 . "ENDBLK") '(8 . "_LU BOIS") ) ) ) it used to work! but not exactly like this. and i receive no error. Regards ! Quote
rkmcswain Posted March 2, 2016 Posted March 2, 2016 Are you specifically trying to make an anonymous block? If so, what block name are you passing to the function? This works for me: (CreationBois "*U1" 8 9 ) Quote
CadFrank Posted March 2, 2016 Author Posted March 2, 2016 I'm trying to pass a block name of a 4x4. It's not annonymous Quote
CadFrank Posted March 2, 2016 Author Posted March 2, 2016 Well I figured it out!! had to put (70 . 1) to (70 . 2) Quote
Tharwat Posted March 2, 2016 Posted March 2, 2016 Hi Frank, Try this minimized codes (defun CreationBois (nom Dim1 Dim2) (if (tblsearch "BLOCK" nom) (princ (strcat "\nBlock name <" nom "> is already existed !")) (progn (entmake (list '(0 . "BLOCK") (cons 2 nom) (cons 10 (list (/ Dim1 2) Dim2)) '(70 . 0) ) ) (mapcar '(lambda (x y) (entmake (list '(0 . "LINE") '(8 . "-LU BOIS") x y ) )) (list '(10 0 0) (cons 10 (list Dim1 0)) (cons 10 (list Dim1 Dim2)) (cons 10 (list 0 Dim1)) '(10 0 0) (cons 10 (list Dim1 0))) (list (cons 11 (list Dim1 0)) (cons 11 (list Dim1 Dim2)) (cons 11 (list 0 Dim2)) '(11 0 0) (cons 11 (list Dim1 Dim2)) (cons 11 (list 0 Dim2))) ) (entmake (list '(0 . "ENDBLK") '(8 . "-LU BOIS") ) ) ) ) (princ) ) Quote
CadFrank Posted March 2, 2016 Author Posted March 2, 2016 I was trying to minimize the code with a foreach If I can't make it. ill try yours. Thank ! Cheers and Beers ! Quote
rkmcswain Posted March 2, 2016 Posted March 2, 2016 I'm trying to pass a block name of a 4x4. It's not annonymous If you pass bitcode 1 to group 70, then the block name must begin with [*] because it will be an anonymous block. You should change the group 70 to 0, not 2 because 2 indicates that you are going to attach attributes to it. Quote
CadFrank Posted March 2, 2016 Author Posted March 2, 2016 Ok so i've come this far and I think theirs something I dont get with the list and quote. (defun CreationBois (Nom Dim1 Dim2) (entmake (list '(0 . "BLOCK") '(100 . "AcDbEntity") '(100 . "AcDbBlockBegin") (cons 2 nom) '(8 . "_LU BOIS") (cons 10 (list (/ Dim1 2) Dim2)) '(70 . 0) ) ) (setq points (list (list (list(0 0)) (list (Dim1 0))) ;;; '((list Dim1 0) (list Dim1 Dim2)) ;;; '((list Dim1 Dim2) (list 0 Dim2)) ;;; '((list 0 Dim1) (list 0 0)) ;;; '((list Dim1 Dim2) (list 0 0)) ;;; '((list Dim1 0) (list 0 Dim2)) ) ) (foreach point points (entmake (list '(0 . "LINE") '(8 . "_LU BOIS") (cons 10 (car points)) (cons 11 (cadr points)) ) ) ) (entmake (list '(0 . "ENDBLK") '(100 . "AcDbBlockEnd") '(100 . "AcDbBlockEnd") '(8 . "_LU BOIS") ) ) ) Now what ever I do it always gives me and error. Any suggestions? Quote
David Bethel Posted March 2, 2016 Posted March 2, 2016 For starters : change (car points) to (car point) and so on There is no real need for the 100 groups as far as I know "BLOCK" group 10 needs x y and z values Quote
Lee Mac Posted March 2, 2016 Posted March 2, 2016 Hint: (cons 1 (list 2 3 4)) == (1 2 3 4) == (list 1 2 3 4) Quote
Lee Mac Posted March 2, 2016 Posted March 2, 2016 I would also suggest entmake'ing the BLOCK and ENDBLK entities on layer "0" to avoid the potential for unpurgeable layers. (defun creationbois ( nom dim1 dim2 ) (if (not (tblsearch "block" nom)) (progn (entmake (list '(0 . "BLOCK") '(8 . "0") (cons 2 nom) (list 10 (/ dim1 2.0) dim2) '(70 . 0))) (foreach x (list (list '(10 0 0) (list 11 dim1 0)) (list (list 10 dim1 0) (list 11 dim1 dim2)) (list (list 10 dim1 dim2) (list 11 0 dim2)) (list (list 10 0 dim2) '(11 0 0)) (list '(10 0 0) (list 11 dim1 dim2)) (list (list 10 0 dim2) (list 11 dim1 0)) ) (entmake (list '(0 . "LINE") '(8 . "_LU BOIS") (car x) (cadr x))) ) (entmake '((0 . "ENDBLK") (8 . "0"))) ) ) ) Quote
CadFrank Posted March 2, 2016 Author Posted March 2, 2016 Well thank everyone! I should've though of putting the list inside the foreach Anywho ! Works like a charm now was looking to make my code smaller also and more readable. Cheers ! Someday ill be an expert like you guys! Quote
Lee Mac Posted March 2, 2016 Posted March 2, 2016 Well thank everyone! I should've though of putting the list inside the foreach You're welcome - but please note that the list is not 'inside' the foreach expression, it still constitutes the list argument for the foreach function (i.e. the 'points' variable in your earlier code). Quote
BIGAL Posted March 3, 2016 Posted March 3, 2016 I would take a slightly diffrent approach to your foreach making the lines if you have 3 lines or 4 or 5 or 20 you need to redo the code every time I would make the list external use Length to find out how many lines and use NTH function for 10&11 pts ((1 2)(3 4)(5 6)(7 ........) Quote
CadFrank Posted March 3, 2016 Author Posted March 3, 2016 You're welcome - but please note that the list is not 'inside' the foreach expression, it still constitutes the list argument for the foreach function (i.e. the 'points' variable in your earlier code). Yeah I might of expressed myself a little off here but it's exactly what I meant. Thanks Lee ! Quote
CadFrank Posted March 3, 2016 Author Posted March 3, 2016 I would take a slightly diffrent approach to your foreach making the lines if you have 3 lines or 4 or 5 or 20 you need to redo the code every time I would make the list external use Length to find out how many lines and use NTH function for 10&11 pts ((1 2)(3 4)(5 6)(7 ........) Not sure what you mean! my list is always different. Do you have more of an exemple . It's always good to see different ways of thinking . Cheers! Quote
BIGAL Posted March 4, 2016 Posted March 4, 2016 If you look at Lees code you have hardcoded 6 lines You could pass any number of lines eg (((0 0)(1 1))((1 1)(11 5 5))((5 5)(22 6))) this would be 3 lines. Quote
CadFrank Posted March 4, 2016 Author Posted March 4, 2016 If you look at Lees code you have hardcoded 6 lines You could pass any number of lines eg (((0 0)(1 1))((1 1)(11 5 5))((5 5)(22 6))) this would be 3 lines. Ok I get what you mean. but this code will always use 6 lines. Since it creates the same type of blocks. But if I would like to use it else where it would but a good idea to put it as you say. Let say i'd like to do a rectangle or a 5 sized polygone. Thanks for your insigh! 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.