Author Topic: How to speed this up?  (Read 3145 times)

0 Members and 1 Guest are viewing this topic.

Bulbasaur

  • Guest
How to speed this up?
« on: June 11, 2014, 03:14:02 AM »
Guys,
I just wrote the code as below and it went slow.
Can anyone tell me how to speed it up?
Code: [Select]
(mapcar '(lambda (p) (entmake (list (cons 0 "circle") (cons 10 p) (cons 40 10)))
             (setq e1 (entlast))
             (command "hatch" "s" e1 "" "p" "solid" "")
             )           
lst
)

Much appreciated!
« Last Edit: June 11, 2014, 04:24:46 AM by Bulbasaur »

Tharwat

  • Swamp Rat
  • Posts: 712
  • Hypersensitive
Re: How to speed up hatching?
« Reply #1 on: June 11, 2014, 03:47:25 AM »
Hi ,

Set the system variable to zero then reset it back at the end of the program .

e.g ;
Code: [Select]
(setq cmd (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
;; Your codes that related to hatch or any command call that used in a lisp routine ;;
(setvar 'CMDECHO cmd)

HasanCAD

  • Swamp Rat
  • Posts: 1423
Re: How to speed up hatching?
« Reply #2 on: June 11, 2014, 03:54:20 AM »
Try out entmake
use this one as a gide
Code: [Select]
;; massoc (Jaysen Long)               ;;
;; Minor Modification by Jvillarreal ;;
;; Extracts info from list by key     ;;
(defun massoc (key alist / x nlist)
 (foreach x alist
   (if
     (eq key (car x))
     (setq nlist (cons x nlist))
   )
 )
 (reverse nlist)
);defun

(defun c:MergeHatch ( / hentinfo ss i ent ent# seedpt# entinfo entinfo2 ent# seedpt# seedpts MergedHatchList)
(while (/= (cdr (assoc 0 hentinfo)) "HATCH")
  (setq hentinfo (car (entsel "\nSelect Hatch Pattern to use:")))
  (If hentinfo (setq hentinfo (entget hentinfo)) (princ "\nMissed. Try again.")))
(while (not ss) (princ "\nSelect hatch entities to merge:")(setq ss (ssget '((0 . "HATCH")))))
(setq MergedHatchList
(list (cons 0 "HATCH")                             
      (cons 100 "AcDbEntity")
      (assoc 8 hentinfo)
      (cons 100 "AcDbHatch")
      (assoc 10 hentinfo)
      (assoc 210 hentinfo)
      (assoc 2 hentinfo)
      (assoc 70 hentinfo)
      (assoc 71 hentinfo)
      (cons 91 (sslength ss))
) i -1 seedpt# 0 ent# 0)

(repeat (sslength ss)
 (setq n -1
       entinfo (entget (ssname ss (setq i (1+ i))))
       entinfo2 (member (assoc 92 entinfo) entinfo)
       entinfo2 (reverse (cdr (member (assoc 75 entinfo2)(reverse entinfo2))))
       ent# (+ ent# (cdr (assoc 91 entinfo)))
       seedpt# (+ seedpt# (cdr (assoc 98 entinfo)))
       seedpts (append seedpts (cdr (member (assoc 98 entinfo) entinfo)))
       MergedHatchList (append MergedHatchList entinfo2)
 )
(entdel (ssname ss i))
)
(setq MergedHatchList (subst (cons 91 ent#)(assoc 91 MergedHatchList) MergedHatchList)
      MergedHatchList
 (append MergedHatchList
   (append
     (reverse (cdr (member (assoc 98 hentinfo)(reverse (member (assoc 75 hentinfo) hentinfo)))))
     (cons (cons 98 seedpt#) seedpts))))
(if (= (cdr (assoc 71 hentinfo)) 1)(setq MergedHatchList (append MergedHatchList '((-3 ("ACAD" (1010 0.0 0.0 0.0)))))))
(entmake MergedHatchList)
(setq ent (entlast))
(if (= (cdr (assoc 71 hentinfo)) 1)
 (mapcar
  '(lambda (x / entlist)
   (setq entlist (entget (cdr x)))
   (entmod (subst (cons 330 ent) (assoc 330 entlist) entlist))
  )
  (massoc 330 MergedHatchList)
 )
)
)
(defun c:MH () (c:MergeHatch))

Bulbasaur

  • Guest
Re: How to speed up hatching?
« Reply #3 on: June 11, 2014, 03:59:12 AM »
Hi ,

Set the system variable to zero then reset it back at the end of the program .

e.g ;
Code: [Select]
(setq cmd (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
;; Your codes that related to hatch or any command call that used in a lisp routine ;;
(setvar 'CMDECHO cmd)

Thanks for replying. I did set system variable to 0. It seems still slow tho. Maybe the problem is the code?

Bulbasaur

  • Guest
Re: How to speed up hatching?
« Reply #4 on: June 11, 2014, 04:02:37 AM »
Try out entmake
use this one as a gide
Code: [Select]
;; massoc (Jaysen Long)               ;;
;; Minor Modification by Jvillarreal ;;
;; Extracts info from list by key     ;;
(defun massoc (key alist / x nlist)
 (foreach x alist
   (if
     (eq key (car x))
     (setq nlist (cons x nlist))
   )
 )
 (reverse nlist)
);defun

(defun c:MergeHatch ( / hentinfo ss i ent ent# seedpt# entinfo entinfo2 ent# seedpt# seedpts MergedHatchList)
(while (/= (cdr (assoc 0 hentinfo)) "HATCH")
  (setq hentinfo (car (entsel "\nSelect Hatch Pattern to use:")))
  (If hentinfo (setq hentinfo (entget hentinfo)) (princ "\nMissed. Try again.")))
(while (not ss) (princ "\nSelect hatch entities to merge:")(setq ss (ssget '((0 . "HATCH")))))
(setq MergedHatchList
(list (cons 0 "HATCH")                             
      (cons 100 "AcDbEntity")
      (assoc 8 hentinfo)
      (cons 100 "AcDbHatch")
      (assoc 10 hentinfo)
      (assoc 210 hentinfo)
      (assoc 2 hentinfo)
      (assoc 70 hentinfo)
      (assoc 71 hentinfo)
      (cons 91 (sslength ss))
) i -1 seedpt# 0 ent# 0)

(repeat (sslength ss)
 (setq n -1
       entinfo (entget (ssname ss (setq i (1+ i))))
       entinfo2 (member (assoc 92 entinfo) entinfo)
       entinfo2 (reverse (cdr (member (assoc 75 entinfo2)(reverse entinfo2))))
       ent# (+ ent# (cdr (assoc 91 entinfo)))
       seedpt# (+ seedpt# (cdr (assoc 98 entinfo)))
       seedpts (append seedpts (cdr (member (assoc 98 entinfo) entinfo)))
       MergedHatchList (append MergedHatchList entinfo2)
 )
(entdel (ssname ss i))
)
(setq MergedHatchList (subst (cons 91 ent#)(assoc 91 MergedHatchList) MergedHatchList)
      MergedHatchList
 (append MergedHatchList
   (append
     (reverse (cdr (member (assoc 98 hentinfo)(reverse (member (assoc 75 hentinfo) hentinfo)))))
     (cons (cons 98 seedpt#) seedpts))))
(if (= (cdr (assoc 71 hentinfo)) 1)(setq MergedHatchList (append MergedHatchList '((-3 ("ACAD" (1010 0.0 0.0 0.0)))))))
(entmake MergedHatchList)
(setq ent (entlast))
(if (= (cdr (assoc 71 hentinfo)) 1)
 (mapcar
  '(lambda (x / entlist)
   (setq entlist (entget (cdr x)))
   (entmod (subst (cons 330 ent) (assoc 330 entlist) entlist))
  )
  (massoc 330 MergedHatchList)
 )
)
)
(defun c:MH () (c:MergeHatch))

Thank you buddy! I personally don't think entmake will make a big difference here. I will have a crack tho! Thanks again

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to speed this up?
« Reply #5 on: June 11, 2014, 05:35:18 AM »
The entmake will probably be faster. But the reason you see hatch slowing everything down is due to it sarting off as a pick point hatch - effectively selecting EVERYTHING visible in the current virtual screen (which could be 1000's of objects). Old problem which adesk never fixed, but made worse when the ribbon was first introduced - if you turn off the ribbon then at least the hatch dialog pops up quicker.

Can't remember when this was introduced though - the HPDLGMODE allows the faster opening of the dialog, but you're still stuck with a slow command-line version. Thus far I know of no way to force a select boundary hatch as the default when the hatch command starts.
« Last Edit: June 11, 2014, 05:41:27 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to speed this up?
« Reply #6 on: June 11, 2014, 10:19:17 AM »
Solid hatch might not help either.  Boundary selection is pretty hard, I'm not certain what could be done to speed it up.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

LE3

  • Guest
Re: How to speed this up?
« Reply #7 on: June 11, 2014, 11:30:15 AM »
just did a quick read here.... did you tried the old bhatch lisp?

don't have my old lisps code handy now, but maybe if you look into here:
http://www.theswamp.org/index.php?topic=9441.msg518783#msg518783

I almost 100% sure that bhatch can be called, the same as bpoly (lisp function).

i.e: ;;;(bpoly pt [ss] [vector]) ===> ;;;(bhatch pt [ss] [vector])

maybe....

hth.-

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to speed this up?
« Reply #8 on: June 11, 2014, 12:00:25 PM »
Yea, I have an old one.  8)

Code: [Select]
;;  Draw a Ying Yang Symbol in a circle
;;  CAB 07/20/2006
(defun c:yingyang (/ ent elst cen lay rad)
  (and
    (setq ent (car (entsel "\nSelect a circle.")))
    (setq elst (entget ent))
    (= "CIRCLE" (cdr (assoc 0 elst)))
    (setq cen (cdr (assoc 10 elst))
          lay (cdr (assoc 8 elst))
          rad (/ (cdr (assoc 40 elst)) 2)
    )
    (entmake
      (list (cons 0 "ARC")
            (cons 8 lay)
            (cons 10 (polar cen (/ pi 2) rad))
            (cons 40 rad)
            (cons 50 (/ pi 2))
            (cons 51 (* pi 1.5))
      )
    )
    (entmake
      (list (cons 0 "ARC")
            (cons 8 lay)
            (cons 10 (polar cen (* pi 1.5) rad))
            (cons 40 rad)
            (cons 50 (* pi 1.5))
            (cons 51 (/ pi 2))
      )
    )
    (command "-BHATCH" "_P" "ANSI31" "1" "45" (polar cen 1.57 rad) "")
  )
  (princ)
)
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.

ronjonp

  • Needs a day job
  • Posts: 7534
Re: How to speed this up?
« Reply #9 on: June 11, 2014, 12:09:01 PM »
Here is another removing the command call for the hatch:
Code: [Select]
(defun c:foo (/ doc e h obj p space)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq space (if (= (getvar 'cvport) 1)
(vla-get-paperspace doc)
(vla-get-modelspace doc)
      )
  )
  (mapcar '(lambda (p)
     (setq e (entmakex (list (cons 0 "circle") (cons 10 p) (cons 40 10))))
     (setq h (vlax-invoke space 'addhatch achatchobject "SOLID" :vlax-true))
     (vlax-invoke h 'appendouterloop (list (vlax-ename->vla-object e)))
     (vla-evaluate h)
   )
  (list (getpoint))
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Bulbasaur

  • Guest
Re: How to speed this up?
« Reply #10 on: June 11, 2014, 09:11:42 PM »
Many thanks guys. I tried 'bhatch' and it's faster...  I use donut in lieu of hatch in this case tho, which is much much faster ... Thanks again :-)