Codigo para crear un bloque

Codigo para crear un bloque

omar.villalobos
Contributor Contributor
737 Views
6 Replies
Message 1 of 7

Codigo para crear un bloque

omar.villalobos
Contributor
Contributor

Buenas noches, me cansé de buscar un codigo que me permita crear un bloque de nombre "MiBloque" y que contenga un circulo de radio 10, sin que me solicite seleccionar nada. Estoy buscando el codigo porque quiero sumarlo a otro que estoy configurando pero lo unico que pude hallar es el siguiente:  

(defun c:cbs ()
  (command "-block" "mi_bloque" "0,0,0")
  (princ "\nBloque 'mi_bloque' creado con éxito.")
  (princ)
)
Lo malo de este, es que me solicita seleccionar un elemento, pero necesito que el circulo de radio 10 se agregue solo sin tener que seleccionarlo. Osea, ejecuto el comando "cbs" y el bloque ya este creado en la lista de bloques del dibujo para poder utilizarlo. Si alguien puede apoyarme con eso. Muchas gracias.
0 Likes
738 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

If its make simple objects like a circle, then using lisp can make a circle at 0,0 with your radius and then make it into a block. That sounds a bit to easy. Do have a range of circle values that you want and make say circ10, circ15, etc.

0 Likes
Message 3 of 7

komondormrex
Mentor
Mentor

Hola,
comprueba lo siguiente

(defun c:cbs nil
	(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) "mi_bloque")))
		(progn
			(vla-addcircle (vla-add (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point '(0 0 0)) "mi_bloque")
						   (vlax-3d-point '(0 0 0))
						   10
			)
			(alert "\nBlock 'mi_bloque' created successfully.")
		)
		(alert "\nBlock 'mi_bloque' is already defined.")

	)
)
0 Likes
Message 4 of 7

calderg1000
Mentor
Mentor

Saludos @omar.villalobos 

Prueba este codigo...

 

(defun c:cbs (/)
    (if (not (tblsearch "BLOCK" "MyBloque"))
      (progn
        (entmake (list (cons 0 "BLOCK")
                       (cons 2 "MyBloque")
                       (cons 10 '(0.0 0.0 0.0))
                       (cons 70 2)
                 )
        )
        (entmake (list (cons 0 "CIRCLE")
                       (cons 8 "Circle")
                       (cons 10 '(0.0 0.0 0.0))
                       (cons 40 10.)
                       (cons 62 1)
                 )
        )
        (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
      )
      (princ"\El Bloque: MyBloque, ya Existe...!!! ")
    )
    (princ)
  )

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 5 of 7

Sea-Haven
Mentor
Mentor

Why not this also.

 

; bubble pt num
; BY ALAN H AUG 2014
 
(defun make_circle ()
  (entmake (list (cons 0 "CIRCLE")
  (cons 8 "0") ; layr
  (cons 10 (list 0 0 0)) ; cen pt
  (cons 40 3.25)     ; rad
  (cons 210 (list 0 0 1))
  (cons 62 256) 
  (cons 39 0)
  (cons 6 "BYLAYER")
   )
  )
) ; DEFUN
 
(defun make_sq ()
; 4 cnr points
  (setq   vertexList
  (list
  (list -3.25 -3.25 0.)
  (list 3.25 -3.25 0.)
  (list 3.25 3.25 0.)
  (list -3.25 3.25 0.)
  ))
  (entmake
    (append 
    (list '(0 . "LWPOLYLINE")
    '(100 . "AcDbEntity")
    '(100 . "AcDbPolyline")
    (cons 90 (length vertexList))
    (cons 70 1)   ; 1 closed : 0 open
    (cons 8 "0")
    (cons 38 0.0)
    (cons 210 (list 0.0 0.0 1.0))
    )
    (mapcar '(lambda (pt) (cons 10 pt)) vertexList)
    )
  ) ; entmake
) ; defun
 
(defun Make_bubble ( )
 
  (entmake (list (cons 0 "BLOCK")
    (cons 2 Blkname)
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))
 
  (if (= resp "C")
  (make_circle)
  (make_sq)
  )
 
  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
       (cons 1 "1")    ; default value
       (cons 2 blkname) ; nblock name
       (cons 3 "Ptnum") ; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD")             ;text style
       (cons 8 "0")    ; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5)           ; text height
       (cons 41 1)     ; X scale
       (cons 50 0)     ; Text rotation
       (cons 51 0)     ; Oblique angle
       (cons 62 256)          ; by layer color 
       (cons 70 0)
       (cons 71 0)     ;Text gen flag
       (cons 72 1)     ; Text Justify hor 1 center
       (cons 73 0)     ; field length
       (cons 74 2)     ; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))
 
  (entmake (list (cons 0 "ENDBLK")))
(command "erase" "L" "") ; do not need linework etc so erase
  (princ)

)
 
(defun C:bub (/ ptnum ptnumb pt pt2 oldsnap chrnum sc curspace)
  (if (= 1 (getvar 'cvport))
  (setq sc 1.0)
  (setq sc (/ 1000.0 (getreal "\nEnter plotting scale")))
  )
 
  (setq oldsnap (getvar "osmode"))
  (setvar "textstyle" "standard")
 
  (setq ptnum (getstring "\nEnter Pt Number or alpha"))
  (setq chrnum (ascii (substr ptnum 1 1))) ; 1st character is number
  (if (< chrnum 58)
  (setq ptnumb (atof ptnum));convert back to a number 
  )
 
 
(while (setq pt (getpoint "\Pick end of line Enter to exit"))
    (setq pt2 (polar pt (/ pi 2.0) 3.25))
    (setvar "osmode" 0)
 
    (if        (< chrnum 58)
    (progn
    (command "-insert" blkname pt sc  "" 0 (rtos ptnumb 2 0))
    (setq ptnumb (+ ptnumb 1))
    )
    (progn 
    (command "-insert" blkname pt sc "" 0 (chr chrnum))
    (setq chrnum (+ chrnum 1))
    )
    )
    (command "move" "L" "" pt pt2)
    (setvar "osmode" 1)
)
 
(setvar "osmode" oldsnap)
(princ)
)       ; end defun
;;;;;; 
; program starts here checking 
(alert "Type Bub to repeat\nYou can do alpha's or numbers\nSquare or circles")
(initget 6 "S s C c")
(setq resp (strcase (Getkword "\nDo you want Circle or Square C or S <C> ")))
(if (or (= resp "C") (= resp nil))
  (setq blkname "SETOUT_POINT_NO")
  (setq blkname "SETOUT_POINT_NOSQ")
)
(if (/= (tblsearch "BLOCK" blkname) NIL)
(PRINC "FOUND")    ; block exists
(Make_bubble)
)
 
(C:BUB)
(princ)
Message 6 of 7

omar.villalobos
Contributor
Contributor

@Sea-Haven, esto es muy interesante, no es lo que estoy buscando en este momento pero sin duda es lo...

0 Likes
Message 7 of 7

omar.villalobos
Contributor
Contributor

Gracias a todos los que me pudieron responder, he encontrado el codigo simple que necesitaba y lo comparto: 

(defun C:crear_bloque ()
 (command
"_.circle" "non" (getvar 'viewctr) 1
"_.block" "NKT-H" "_non" (getvar 'viewctr) "_last" ""
)
(prin1)
)

0 Likes