Author Topic: ENTMAKE function  (Read 38589 times)

0 Members and 3 Guests are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ENTMAKE function
« Reply #75 on: April 05, 2011, 10:15:59 AM »
Get the latest function here:  http://www.theswamp.org/index.php?topic=31145

You will need to use something like this:  [just an example, no error checking]
Code: [Select]
(defun c:test(/ LowerLeft LastEnt NewEnts)
  (vl-load-com)

;;  CAB version 03.01.2008
;;  returns a list of enames and not a selection set.

;;  CAB - get last entity in datatbase
;;  An entity name, or nil, if there are no entities in the current drawing.
(defun GetLastEnt ( / ename result )
  (if (setq result (entlast))
    (while (setq ename (entnext result))
      (setq result ename)
    )
  )
  result
)

;;  CAB 09.17.08 - return a list of new enames
;;  if ename is nil then return all objects in DWG
(defun GetNewEntities (ename / new)
  (cond
    ((or (null ename) (null (setq new (list (entnext))))))
    ((eq 'ENAME (type ename))
      (while (setq ename (entnext ename))
        (if (entget ename) (setq new (cons ename new)))
      )
    )
    ; ((alert "Ename wrong type."))
  )
  new
)


  ;;  returns a point list in WCS coordinates ((lower left)(upper right))
  (defun boundingbox (lst / ptlst mnpt mxpt)
    (mapcar '(lambda (x)
               (vla-getboundingbox (vlax-ename->vla-object x) 'mnpt 'mxpt)
               (setq ptlst (cons (vlax-safearray->list mnpt) ptlst))
               (setq ptlst (cons (vlax-safearray->list mxpt) ptlst))
             )
            lst
    )
    ;;following by Tony Tanzillo
    (list
      (apply 'mapcar (cons 'min ptlst))
      (apply 'mapcar (cons 'max ptlst))
    )
  )

  (setq LastEnt (GetLastEnt))
  (c:eMake)
  (setq NewEnts (vl-remove-if '(lambda(x) (= "VIEWPORT" (cdr (assoc 0 (entget x))))) (GetNewEntities LastEnt)))
  (setq LowerLeft (car (boundingbox NewEnts)))
  (command "._move")
  (mapcar 'command NewEnts)
  (command "" "_non" LowerLeft)

)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VVA

  • Newt
  • Posts: 166
Re: ENTMAKE function
« Reply #76 on: June 10, 2011, 02:23:16 AM »
Creation of hatch with the instruction of a pattern, a angle and scale.

Code: [Select]
(defun entmakex-hatch (L a n s)
 ;; By ElpanovEvgeniy
 ;; L - list point
 ;; A - angle hatch
 ;; N - name pattern
 ;; S - scale

 ;; returne - hatch ename
 (entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
[color=red]          '(2 . "ANSI31")[/color]
          (if (= n "SOLID")
           '(70 . 1)
           '(70 . 0)
          ) ;_  if
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
           (mapcar '(lambda (a)
                     (apply 'append
                            (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                                  (mapcar '(lambda (b) (cons 10 b)) a)
                                  '((97 . 0))
                            ) ;_  list
                     ) ;_  apply
                    ) ;_  lambda
                   l
           ) ;_  mapcar
    ) ;_  apply
    (list '(75 . 0)
          '(76 . 1)
          (cons 52 a)
          (cons 41 s)
          '(77 . 0)
          '(78 . 1)
          (cons 53 a)
          '(43 . 0.)
          '(44 . 0.)
          '(45 . 1.)
          '(46 . 1.)
          '(79 . 0)
          '(47 . 1.)
          '(98 . 2)
          '(10 0. 0. 0.0)
          '(10 0. 0. 0.0)
          '(451 . 0)
          '(460 . 0.0)
          '(461 . 0.0)
          '(452 . 1)
          '(462 . 1.0)
          '(453 . 2)
          '(463 . 0.0)
          '(463 . 1.0)
          '(470 . "LINEAR")
    ) ;_  list
   ) ;_  list
  ) ;_  apply
 ) ;_  entmakex
) ;_  defun
Little correct for solid hatch
Code: [Select]
(defun entmakex-hatch (L a n s)
;; By ElpanovEvgeniy
;; L - list of list point. like ((pt11 pt12 pt13)(pt21 pt22 pt23))
;; A - angle hatch
;; N - name pattern
;; S - scale
;; returne - hatch ename
;;USE
;|
(entmakex-hatch '(((538.794 584.563) (895.629 584.563) (895.629 997.377) (538.794 997.377))
                  ((386.809 345.13) (670.955 345.13) (670.955 855.369) (386.809 855.369))
                 )
                (/ pi 2)
                "ANSI31"
                2.
) ;_  entmakex-hatch
(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"SOLID"
2.
)
(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"ANSI31"
2.
)
(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"ANSI32"
2.
)
|;
(entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
          (cons 2 n)
          (if (= n "SOLID")
           '(70 . 1)
           '(70 . 0)
          ) ;_  if
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
           (mapcar '(lambda (a)
                     (apply 'append
                            (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                                  (mapcar '(lambda (b) (cons 10 b)) a)
                                  '((97 . 0))
                            ) ;_  list
                     ) ;_  apply
                    ) ;_  lambda
                   l
           ) ;_  mapcar
    ) ;_  apply
    (if (= n "SOLID")
     (list '(75 . 0)
          '(76 . 1)
;;;          (cons 52 a)
;;;          (cons 41 s)
;;;          '(77 . 0)
;;;          '(78 . 1)
;;;          (cons 53 a)
;;;          '(43 . 0.)
;;;          '(44 . 0.)
;;;          '(45 . 1.)
;;;          '(46 . 1.)
;;;          '(79 . 0)
          '(47 . 1.)
          '(98 . 2)
          '(10 0. 0. 0.0)
          '(10 0. 0. 0.0)
          '(450 . 0)
          '(451 . 0)
          '(460 . 0.0)
          '(461 . 0.0)
          '(452 . 0)
          '(462 . 0.0)
          '(453 . 2)
          '(463 . 0.0)
          '(63 . 256)
          '(463 . 1.0)
          '(63 . 256)
          '(470 . "LINEAR")
    ) ;_  list
    (list '(75 . 0)
          '(76 . 1)
          (cons 52 a)
          (cons 41 s)
          '(77 . 0)
          '(78 . 1)
          (cons 53 a)
          '(43 . 0.)
          '(44 . 0.)
          '(45 . 1.)
          '(46 . 1.)
          '(79 . 0)
          '(47 . 1.)
          '(98 . 2)
          '(10 0. 0. 0.0)
          '(10 0. 0. 0.0)
;;;          '(451 . 0)
;;;          '(460 . 0.0)
;;;          '(461 . 0.0)
;;;          '(452 . 1)
;;;          '(462 . 1.0)
;;;          '(453 . 2)
;;;          '(463 . 0.0)
;;;          '(463 . 1.0)
          '(470 . "LINEAR")
    ) ;_  list
      )
   ) ;_  list
  ) ;_  apply
) ;_  entmakex
) ;_  defun
Use:
Code: [Select]
(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"SOLID"
2.
)

(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"ANSI31"
2.
)

(entmakex-hatch
(list
  (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"ANSI32"
2.
)


andy_lee

  • Newt
  • Posts: 147
Re: ENTMAKE function
« Reply #77 on: September 26, 2014, 12:51:15 AM »
A lot of useful examples .thanks!
andy.
Best regards.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ENTMAKE function
« Reply #78 on: September 26, 2014, 08:12:47 AM »
Glad to help. Enjoy your stay here at the Swamp.  8)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

andy_lee

  • Newt
  • Posts: 147
Re: ENTMAKE function
« Reply #79 on: September 29, 2014, 06:58:14 AM »
Glad to help. Enjoy your stay here at the Swamp.  8)

Thanks CAB.  :wink:
andy.
Best regards.