Jump to content

Create block with Entmake


CadFrank

Recommended Posts

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 !

Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

Hi Frank,

 

Try this minimized codes :D

 

(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)
 )

Link to comment
Share on other sites

I was trying to minimize the code with a foreach :)

 

If I can't make it. ill try yours.

 

Thank !

 

Cheers and Beers !

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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")))
       )
   )
)

Link to comment
Share on other sites

Well thank everyone!

 

I should've though of putting the list inside the foreach :(

 

Anywho !

 

Works like a charm now :D was looking to make my code smaller also and more readable.

 

Cheers !

 

Someday ill be an expert like you guys!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 8)........)

Link to comment
Share on other sites

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 ! :)

Link to comment
Share on other sites

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 8)........)

 

Not sure what you mean! my list is always different. Do you have more of an exemple :D.

 

It's always good to see different ways of thinking .

 

Cheers!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...