Disable screen updates for a length of time?

Disable screen updates for a length of time?

SORONW
Advocate Advocate
1,868 Views
9 Replies
Message 1 of 10

Disable screen updates for a length of time?

SORONW
Advocate
Advocate

Is there a way to disable display updates through AutoLisp? I've got a piece of code that steps through a number of blocks. The problem arises that the frequent opening and closing of "bedit" essentially turns the screen into a strobe light.  Aside from the annoyance of the flashing screen, I don't want to be even remotely close to the possibility of triggering an epileptic episode.

 

Any ideas? I've considered just temporarily changing the block editors background color to minimize the effect but I'd rather not change other users settings unless necessary. 

0 Likes
1,869 Views
9 Replies
Replies (9)
Message 2 of 10

CodeDing
Advisor
Advisor

@SORONW ,

 

I'm not 100% but there MIGHT be a way if using VBA..

But I think instead of asking if we can turn off screen updating, we should probably be asking if there is a different method to update your blocks?

 

What are you doing to your block that requires you to use BEDIT? Are you adding an entity to your block? Or editing something? deleting?

 

Perhaps what you're trying to accomplish can be done without using BEDIT at all. Can you help by describing your workflow?

 

Best,

~DD

0 Likes
Message 3 of 10

SORONW
Advocate
Advocate

 

Ok, here's the snippet of code:

(defun C:FabUpdate (/ BlkList )
 (vl-load-com)
 (setq blklist nil)
 ;test connection
(if (connect) (progn (princ "\n\n Connection Error: Please Reload ADOLISP_LIBRARY.lsp & FAB.lsp") (quit) ))
;Get List of all Defined Block in the Document...
(setq BlockTable (vla-get-blocks (vla-get-activedocument (vlax-get-Acad-Object))))
	(vlax-for each BlockTable
		(setq BlkList (cons (vla-get-Name each) BlkList))
		(setq BlkList (cons (vla-get-Comments each) BlkList))
	)
	(if BlkList
    (reverse BlkList)
	)
;Main Loop
(foreach item BlkList
	(progn (cond ((vl-string-search "MAJOR" item )
			(setq dwg (vl-String-right-trim " MAJOR" item ))
			(command "_.-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg)
			(drawPerimeter (list 0 0 0) 1 section)
			(setq fabdata (cdr fabdata))
			(fabDraw fabdata (list 0 0 0) 1)
			(command "_.-bedit" "S" item "" )
			(command "_.bclose" "_sav")
			(princ "\nMajor Face Successful!")
		)
		((vl-string-search "MINOR" item )
			(setq dwg (vl-String-right-trim " MINOR" item))
			(command "-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg)
			(drawPerimeter (list 0 0 0) 2 section)
			(setq fabdata (cdr fabdata))
			(fabDraw fabdata (list 0 0 0) 2)
			(command "-bedit" "S" item "" )
			(command "_.bclose" "_sav")
		)
	)
	)
)
(alert "\nAll Blocks Current")
(princ)
	
);defun

The idea is that it checks for any of our generated blocks in the drawing (from a separate command), and replaces the existing definition with the current definition from a fabrication database.

 

 

 

 

0 Likes
Message 4 of 10

CodeDing
Advisor
Advisor

@SORONW ,

 

Thank you for the snippet. Do any of your new blocks use attributes? There are a handful of user-defined functions in your snippet that I am curious what they accomplish.

 


@SORONW wrote:

 

(defun C:FabUpdate (/ BlkList )
 (vl-load-com)
 (setq blklist nil)
 ;test connection
(if (connect) (progn (princ "\n\n Connection Error: Please Reload ADOLISP_LIBRARY.lsp & FAB.lsp") (quit) ))
;Get List of all Defined Block in the Document...
(setq BlockTable (vla-get-blocks (vla-get-activedocument (vlax-get-Acad-Object))))
	(vlax-for each BlockTable
		(setq BlkList (cons (vla-get-Name each) BlkList))
		(setq BlkList (cons (vla-get-Comments each) BlkList))
	)
	(if BlkList
    (reverse BlkList) ;<-- this is not being stored as a variable,
	)             ;    therefore, this 'if' statement can be removed entirely.
;Main Loop
(foreach item BlkList
	(progn (cond ((vl-string-search "MAJOR" item )
			(setq dwg (vl-String-right-trim " MAJOR" item ))
			(command "_.-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg) ;<-- what does this 'search' for?
			(drawPerimeter (list 0 0 0) 1 section) ;<-- what are you drawing, and where was 'section' defined?
			(setq fabdata (cdr fabdata)) ;<-- where was 'fabdata' defined? and what is it?
			(fabDraw fabdata (list 0 0 0) 1) ;<-- what does 'fabDraw' actually draw?
			(command "_.-bedit" "S" item "" )
			(command "_.bclose" "_sav")
			(princ "\nMajor Face Successful!")
		)
		((vl-string-search "MINOR" item )
			(setq dwg (vl-String-right-trim " MINOR" item))
			(command "-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg)
			(drawPerimeter (list 0 0 0) 2 section)
			(setq fabdata (cdr fabdata))
			(fabDraw fabdata (list 0 0 0) 2)
			(command "-bedit" "S" item "" )
			(command "_.bclose" "_sav")
		)
	)
	)
)
(alert "\nAll Blocks Current")
(princ)
	
);defun

 


 

0 Likes
Message 5 of 10

SORONW
Advocate
Advocate

@CodeDing 

 

None of these new blocks use attributes. The user functions are all for data processing and drawing of the shape.

Here's an example of a finished part:

 
 

Capture.PNG

All the parts would either be pultrusions/extrusions with a predefined profile.

 

Search pulls from the database and defines an number of variables (Height, width, length, profile of shape, ect...)  This is where fabdata comes from .

(defun Search ( Drawnum / Result )
	(progn
		;(
		;Retrieve Part data
		(princ "Retrieving part data")
		(SELQuery(strcat "SELECT PART_ID, SECTION, LENGTH, FORMAT, REV FROM PART WHERE STATUS BETWEEN 0 AND 2 AND NAME = '" Drawnum "';"))
		(setq partdata result) ;Search parts list for drawing number to retrieve rows database. Returns a nested list.
		(setq 	PART_ID	(nth (vl-position "PART_ID" (car partdata)) (cadr partdata))) ;Convert item from list into manipulable variabler
		(setq	section	(nth (vl-position "SECTION" (car partdata)) (cadr partdata)))
		(setq	plength	(nth (vl-position "LENGTH" (car partdata)) (cadr partdata)))
		(setq	format	(nth (vl-position "FORMAT" (car partdata)) (cadr partdata)))
		(setq	rev		(nth (vl-position "REV" (car partdata)) (cadr partdata)))
		(SELQuery(strcat "SELECT NAME, WIDTH, HEIGHT, SYMMETRY FROM SECTION WHERE NAME = '" section "';"))
		(setq sectiondata result) ;Search parts list for drawing number to retrieve rows database. Returns a nested list.
		(setq section (nth (vl-position "NAME" (car sectiondata)) (cadr sectiondata)))
		(setq width (nth (vl-position "WIDTH" (car sectiondata)) (cadr sectiondata)))
		(setq height (nth (vl-position "HEIGHT" (car sectiondata)) (cadr sectiondata)))
		(setq symmetry (nth (vl-position "SYMMETRY" (car sectiondata)) (cadr sectiondata)))
		(setq thickness	(distof (substr section (+ (vl-string-position (ascii "x") section 0 T) 2))))
		(SELQuery(strcat "SELECT TYPE, FACE, SIDE, LOCATION, OFFSET, PARAMETER_1, PARAMETER_2, PARAMETER_3 FROM FABRICATION WHERE PART_ID = '" (itoa PART_ID) "';"))
		(setq fabdata result) ;Search parts list for drawing number to retrieve rows database. Returns a nested list.
		;)
		;(princ)
	);progn
)

Inside of search is SELquery which is just a wrapper for the Adolisp function "ADOLISP_DoSQL".

 

Fabdata is a nested list of lists showing each fabrication used on the shape, where each nested list is the location and specifications of each fab.

Command: !fabdata
(("HOLE" 1 3 46.875 1.5 0.5625 0.0 0.0) ("HOLE" 1 3 52.5625 1.5 0.5625 0.0 0.0) ("R-CUT" 1 3 54.9375 3.0 -43.4518 0.0 0.0))

 

DrawPerimeter the variables defined in search and creates the outer boundary of the major and minor face of each part. It then checks the profile to create the correct hidden lines as necessary. 

 

Lastly FabDraw is where the nested lists of fabdata are processed and drawn.

 

 

You mentioned VBA, and I looked into it a bit. It appears disabling screen updating could be a solution https://www.automateexcel.com/vba/turn-off-screen-updating/.

 

Also, after thinking about it, it might almost be easier just to prompt the user to click an available point and have the parts drawn up and removed there. That could avoid stepping through the bedit, but might cause issues related to trimming. I'm thinking Ill give that a shot and see where it gets me.

 

@SORONW ,

 

Thank you for the snippet. Do any of your new blocks use attributes? There are a handful of user-defined functions in your snippet that I am curious what they accomplish.

 

@SORONW wrote:

 

(defun C:FabUpdate (/ BlkList )
 (vl-load-com)
 (setq blklist nil)
 ;test connection
(if (connect) (progn (princ "\n\n Connection Error: Please Reload ADOLISP_LIBRARY.lsp & FAB.lsp") (quit) ))
;Get List of all Defined Block in the Document...
(setq BlockTable (vla-get-blocks (vla-get-activedocument (vlax-get-Acad-Object))))
	(vlax-for each BlockTable
		(setq BlkList (cons (vla-get-Name each) BlkList))
		(setq BlkList (cons (vla-get-Comments each) BlkList))
	)
	;(if BlkList
;   (reverse BlkList) ;<-- this is not being stored as a variable,
	;)             ;    therefore, this 'if' statement can be removed entirely.
;Main Loop
(foreach item BlkList
	(progn (cond ((vl-string-search "MAJOR" item )
			(setq dwg (vl-String-right-trim " MAJOR" item ))
			(command "_.-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg) ;<-- what does this 'search' for?
			(drawPerimeter (list 0 0 0) 1 section) ;<-- what are you drawing, and where was 'section' defined?
			(setq fabdata (cdr fabdata)) ;<-- where was 'fabdata' defined? and what is it?
			(fabDraw fabdata (list 0 0 0) 1) ;<-- what does 'fabDraw' actually draw?
			(command "_.-bedit" "S" item "" )
			(command "_.bclose" "_sav")
			(princ "\nMajor Face Successful!")
		)
		((vl-string-search "MINOR" item )
			(setq dwg (vl-String-right-trim " MINOR" item))
			(command "-bedit" item "" )
			(setq ss (ssget "_A" ))
				(repeat (setq i (sslength ss)) 
				(entdel (ssname ss (setq i (1- i))))
				)
			(search dwg)
			(drawPerimeter (list 0 0 0) 2 section)
			(setq fabdata (cdr fabdata))
			(fabDraw fabdata (list 0 0 0) 2)
			(command "-bedit" "S" item "" )
			(command "_.bclose" "_sav")
		)
	)
	)
)
(alert "\nAll Blocks Current")
(princ)
	
);defun

 

 

0 Likes
Message 6 of 10

ronjonp
Advisor
Advisor

As @CodeDing mentioned .. you most likely don't need to use bedit to accomplish this. Or you could take a nap while the code is running to prevent seizures 😅.

 

Post the code for your subs and a sample drawing .. I bet we could improve upon this.

 

Or put this at the beginning of your code:

 

(if (setq *shell (vlax-create-object "Shell.Application"))
  (vlax-invoke *shell 'minimizeall)
)

And this at the end 🙂

 

(and *shell (vlax-invoke *shell 'undominimizeall))
0 Likes
Message 7 of 10

Sea-Haven
Mentor
Mentor

Maybe do a script make a new dwg with the updated block, close then insert into current dwg and accept the overwrite block and attsync.

0 Likes
Message 8 of 10

CodeDing
Advisor
Advisor

@SORONW ,

 

Do you have experience using the entmake function?

This is how you would potentially remove your BEDIT reliance.

 

If I knew how you are drawing your parts, we could replace these highlighted sections (ignore my edits for now, just seeing if/what I could help clean up in your existing code)...

(defun C:FabUpdate ( / blkList)
;helper function(s)
  (defun GetAllBlocks ( / blkList blk)
    (setq blkList '() blk (tblnext "BLOCK" t))
    (while blk
      (setq blkList (cons (cdr (assoc 2 blk)) blkList) blk (tblnext "BLOCK"))
    );while
    blkList
  );defun
(vl-load-com)
;test connection
(if (connect) (progn (princ "\n\n Connection Error: Please Reload ADOLISP_LIBRARY.lsp & FAB.lsp") (quit) ))
;Get List of all Defined Block in the Document...
(setq blkList (mapcar 'strcase (GetAllBlocks)))
;Main Loop
(foreach blkName blkList
  (cond
    ((wcmatch blkName "* MAJOR")
      ; vv check the help for this function (vl-string-right-trim), it may not act as you think it does.
      ;(setq dwg (vl-String-right-trim " MAJOR" blkName ))
      (setq dwg (substr blkName 1 (- (strlen blkName) 6)))
      (command "_.-bedit" blkName "" )
      (setq ss (ssget "_A" ))
      (repeat (setq i (sslength ss)) 
	(entdel (ssname ss (setq i (1- i))))
      )
      (search dwg)
(drawPerimeter (list 0 0 0) 1 section) (setq fabdata (cdr fabdata)) (fabDraw fabdata (list 0 0 0) 1) (command "_.-bedit" "S" blkName "" ) (command "_.bclose" "_sav") (princ "\nMajor Face Successful!") ) ((wcmatch blkName "* MINOR") ;(setq dwg (vl-String-right-trim " MINOR" blkName)) (setq dwg (substr blkName 1 (- (strlen blkName) 6))) (command "-bedit" blkName "" ) (setq ss (ssget "_A" )) (repeat (setq i (sslength ss)) (entdel (ssname ss (setq i (1- i)))) ) (search dwg) (drawPerimeter (list 0 0 0) 2 section) (setq fabdata (cdr fabdata)) (fabDraw fabdata (list 0 0 0) 2) (command "-bedit" "S" blkName "" ) (command "_.bclose" "_sav")
(princ "\nMinor Face Successful!") ) );cond );foreach (alert "\nAll Blocks Current") (princ) );defun

...with potentially just a single function...

(defun FabDraw ( / )
  (entmakex '((0 . "BLOCK") (2 . "MyBlockName") (70 . 0) (10 0.0 0.0 0.0))))
  (entmakex (list '(0 . "POINT") (cons 10 (getpoint))))
  ;...
  (entmakex '((0 . "ENDBLK"))))
);defun

 

Also, it appears you have another global variable named result (which I assume is defined in the SELQuery function). You use this result variable to define: partdata, sectiondata, and fabdata. Why do you define these 4 things all the same, when you could just use 1 global variable?

 

Let me know what you think of that. Best,

~DD

0 Likes
Message 9 of 10

rmC86GJ
Participant
Participant

I see OP's question as very reasonable; there are situations in which one needs exactly that - to disable screen updates while lisp code runs. 

For example, if instead of manipulating blocks, the program needs to zoom closely around multiple small entities one by one in order to do SSGET selection, no tricks would help. 

What's more, being able to disable screen/s for the time code runs would greatly improve speed - in terms of times faster. I tested this and for my test, I got a huge difference: from 3 seconds to 18 seconds.

This would be similar to some HP calculators we used in the past, they could turn off display while code runs to save batteries and time, I guess.

0 Likes
Message 10 of 10

rmC86GJ
Participant
Participant

@ronjonp wrote:

...

Or put this at the beginning of your code:

 

(if (setq *shell (vlax-create-object "Shell.Application"))
  (vlax-invoke *shell 'minimizeall)
)

And this at the end 🙂

 

(and *shell (vlax-invoke *shell 'undominimizeall))

This is a step in the right direction, even though not exactly what is needed. Still nearly halved the time mentioned above: 19:5 vs 11:5 seconds on my setup. Looks like 'undominimizeall doesn't do what's expected, but I can live with it 🙂

 

Thanks

0 Likes