Jump to content

Any way to speed up this code?


Guest kruuger

Recommended Posts

Guest kruuger

Hello

 

I create a simple lisp routine to freeze required layer in viewport. Everything works fine but when we got a lot of layers and xref's programs not works to fast. sometimes it takes more then 10sec to finish.

 

Is there any way to speed up this routine? Change some functions, maybe do this in completely different way?

Any ideas?

 

thanks

kruuger

Scale VP.lsp

Link to comment
Share on other sites

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    12

  • Lee Mac

    6

  • Se7en

    2

  • MSasu

    1

Top Posters In This Topic

Guest kruuger
Try to access layer's associated lists and modify parameters instead of using command function.

 

Regards,

hmm, i'm not sure if i understood you correct?

do you mean (vla-put-freeze aNewLayer :vlax-true)?

i think i can't use this because it freeze layer in drawings not in selected vport.

 

I try also with XDATA code 1003 for vport, but entmode can't update the viewport.

 

kruuger

Link to comment
Share on other sites

If you are stuck with command, put the layers into a comma delimited string so you only have to execute VPLayer once.

Link to comment
Share on other sites

Guest kruuger
If you are stuck with command, put the layers into a comma delimited string so you only have to execute VPLayer once.

i'm not sure this will help because i want to freeze all layers *dims* and *text* (use mask for that).

 

krugger

Link to comment
Share on other sites

i'm not sure this will help because i want to freeze all layers *dims* and *text* (use mask for that).

 

krugger

Then use "*dims*,*text*"
Link to comment
Share on other sites

Guest kruuger

oo yes, it works faster.

but i noticed one thing. at beginning i freeze these layers:

"*DIM*,*TEXT_*,A-HAT1*,*veneer*"

after that i restore, for example for scale 3" layer *veneer*. restoring takes a lot of time so...

 

my idea is only to freeze and not restore. but how to not freeze, for example for scale 16 layer *DIM16*,*TEXT_16?

is it possible to do this with wcmatch? (freeze *DIM* but exclude *DIM16*)

 

thanks

kruuger

Link to comment
Share on other sites

Try something like this:

 

(defun _LayerFilter (include exclude / d s)
 ;; include - filter string to include matching ("" if not needed)
 ;; exclude - filter string to exclude matching ("" if not needed)
 ;; Alan J. Thompson
 (while (setq d (tblnext "layer" (null d)))
   (if (and (wcmatch (setq d (strcase (cdr (assoc 2 d)))) (strcase include))
            (not (wcmatch (strcase d) (strcase exclude)))
       )
     (if s
       (setq s (strcat s "," d))
       (setq s d)
     )
   )
 )
 s
)

 

 

eg.

(_layerfilter "*dim*" "*dim16*")

Link to comment
Share on other sites

Alan your code works perfect. now wihtout restoring layers lisp should work very fast.

 

thank you,

kruuger

 

You're welcome. Enjoy. :)

Link to comment
Share on other sites

Maybe someone can help you incorporate something along the lines of entmod or vla-put-freeze so you dont have to use command at all (not that command is bad; I use it quite a bit myself)...you know, for fun.

 

Here is a small (funny *lol*) example of how you can freeze the current layer using entmod by just quickly flipping a bit.

 

( (lambda ( / laylst )
  (setq laylst (entget (tblobjname "LAYER" (getvar 'CLAYER))))
  (entmod 
   (subst 
    (cons 70 (boole 6 (cdr (assoc 70 laylst)) 1)) 
    (assoc 70 laylst) 
    laylst))) )

Link to comment
Share on other sites

Nice one Se7en, this is what I had:

 

;; Freeze/Thaw Layer  ~  Lee Mac
;; layer - layer table object (tblobjname)
;; freeze - 1 = Freeze Layer
;;          0 = Thaw Layer

(defun FTLayer ( layer freeze / dx70 el )
 (setq dx70 (cdr (assoc 70 (setq el (entget layer)))))
 (entmod
   (subst
     (cons 70 (boole (+ 4 (* freeze 3)) 1 dx70)) (assoc 70 el) el)))

Link to comment
Share on other sites

*smile* Also very nice.

 

Too bad I only have one more trick up my sleeve.

 

What if we improve the argument handling ability of our little concoction?

 

;; Argument:
;;          t or non nil: thaw, or leave thawn
;;          0 or false: freeze, or leave frozen
;;          Any value except 0 = true
(cond ((= 0 argument) 7) (argument 2) (7))

 

(defun frlay ( argument / laylst )
  ;; Argument:
  ;;          t or non nil: thaw, or leave thawn
  ;;          0 or false: freeze, or leave frozen
  ;;          Any value except 0 = true
  (setq laylst (entget (tblobjname "LAYER" (getvar 'CLAYER))))
  (entmod
   (subst
    (cons 70 (boole (cond ((= 0 argument) 7) (argument 2) (7)) (cdr (assoc 70 laylst)) 1))
    (assoc 70 laylst)
    laylst)))

Link to comment
Share on other sites

Try this Kruuger:

 

;; Freeze Layer in Viewport (Lee Mac)
;; Arguments:
;; layername [sTR]  ~  valid Layer Name
;; flag      [iNT]  ~  1 = freeze in vp
;;                     0 = thaw in vp

(defun FreezeInViewport ( layername flag )
 ;; © Lee Mac  ~  20.06.10

 (
   (lambda ( object )
     (if object
       (entmod
         (subst
           (cons 70
             (boole (+ (* flag 5) 2)
               (cdr
                 (assoc 70
                   (entget object)
                 )
               )
               2
             )
           )
           (assoc 70 (entget object))
           (entget object)
         )
       )
     )
   )
   (tblobjname "LAYER" layername)
 )
)

Link to comment
Share on other sites

Guest kruuger
Try this Kruuger:

 

;; Freeze Layer in Viewport (Lee Mac)
;; Arguments:
;; layername [sTR]  ~  valid Layer Name [sTR]
;; flag      [iNT]  ~  1 = freeze in vp
;;                     0 = thaw in vp

(defun FreezeInViewport ( layername flag )
 ;; © Lee Mac  ~  20.06.10

 (
   (lambda ( object )
     (if object
       (entmod
         (subst
           (cons 70
             (boole (+ (* flag 5) 2)
               (cdr
                 (assoc 70
                   (entget object)
                 )
               )
               2
             )
           )
           (assoc 70 (entget object))
           (entget object)
         )
       )
     )
   )
   (tblobjname "LAYER" layername)
 )
)

 

hmm, nothing happen. is missing something for object?

kruuger

Link to comment
Share on other sites

Guest kruuger

return:

Command: (FREEZEINVIEWPORT "DRAWER3" 0)
((-1 . <Entity name: 7c7bb798>) (0 . "LAYER") (330 . <Entity name: 7ec41c10>) 
(5 . "2B23") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 
. "DRAWER3") (70 . 0) (62 . 3) (6 . "Continuous") (290 . 1) (370 . -3) (390 . 
<Entity name: 7ec41c78>) (347 . <Entity name: 7ec41f00>))

Command: (FREEZEINVIEWPORT "DRAWER3" 1)
((-1 . <Entity name: 7c7bb798>) (0 . "LAYER") (330 . <Entity name: 7ec41c10>) 
(5 . "2B23") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 
. "DRAWER3") (70 . 2) (62 . 3) (6 . "Continuous") (290 . 1) (370 . -3) (390 . 
<Entity name: 7ec41c78>) (347 . <Entity name: 7ec41f00>))

any difference is for code 70.

k.

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