Disable adding grid when creating a viewport

Disable adding grid when creating a viewport

Browning_Zed
Advocate Advocate
946 Views
14 Replies
Message 1 of 15

Disable adding grid when creating a viewport

Browning_Zed
Advocate
Advocate

Hi all.

 

I have a question about how to disable automatic grid addition in the viewport when creating a new viewport. The problem is that if the GRIDMODE system variable is set to 1, then when a new viewport is created using the "_-vports" command, the grid is activated in the created viewport. In this regard, my question: is it possible to disable the addition of a grid, create a reactor so that when the "_-vports" command is run, the GRIDMODE system variable is set to 0, and after the command is executed, the GRIDMODE variable should return to 1? If this is not possible, in this case, is it possible to switch the variable GRIDMODE 0 when switching to Paper Space, and setting GRIDMODE 1 when switching to Model Space? Unfortunately I do not know how to create reactors, so I am asking this question here.

0 Likes
Accepted solutions (2)
947 Views
14 Replies
Replies (14)
Message 2 of 15

ВeekeeCZ
Consultant
Consultant

You can possibly use something like this when you're done with -vports.

(command-s "_.-vports")

(setpropertyvalue (entlast) "GridOn" 0)

Message 3 of 15

Browning_Zed
Advocate
Advocate

This solves the problem, but requires the creation of an additional command. Something like that:

(defun c:VportNonGrid nil
	(command-s "_.-vports")
	(setpropertyvalue (entlast) "GridOn" 0)
)

But I would like to get by with the standard "_-vports" command.

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

@Browning_Zed wrote:

This solves the problem, but requires the creation of an additional command. ....

But I would like to get by with the standard "_-vports" command.


You can UNDEFINE the VPORTS command, and make your version the new definition of it:

 

(command "_.undefine" "VPORTS")
(defun c:VPORTS nil
  (command-s "_.-vports")
  (setpropertyvalue (entlast) "GridOn" 0)
)

 

Kent Cooper, AIA
0 Likes
Message 5 of 15

Browning_Zed
Advocate
Advocate

I meant that I need to call the command by pressing the standard button for creating a viewport (the button located on the ACAD.cuix ribbon), without changing the macro of this button.

0 Likes
Message 6 of 15

Kent1Cooper
Consultant
Consultant

@Browning_Zed wrote:

I meant that I need to call the command by pressing the standard button for creating a viewport (the button located on the ACAD.cuix ribbon), without changing the macro of this button.


I believe [I'm not going to set it up to test] that if you load that UNDEFINE-and-make-new-definition code, you will get that new definition when you use that ribbon button, without changing anything about the ribbon button.  I do the same with OFFSET, for which I have made a new definition that lets me change the Offset distance within the same running of the command, rather than needing to end it and start it again to set a new distance.  When I use the OFFSET button in the ribbon, it invokes _offset, and uses my new definition.

 

I don't typically use the ribbon button to make a new paper space Viewport, and I'm not finding where it is quickly to check.  But if what it invokes is [as you have posted]  _-vports , and does not have the period/decimal-point before the command name [which is needed in the new definition to call the native command], it should use the new definition, without changing the button in any way.

Kent Cooper, AIA
0 Likes
Message 7 of 15

Browning_Zed
Advocate
Advocate

It doesn't work in my case. More details:
1. The standard button on the ribbon invokes the "_-vports" command.
2. I loaded the lsp file with the code you posted above.
3. The "_-vports" command still adds the grid after loading your code.
4. But if I run the "VPORTS" command, then the program algorithm works as it should - a viewport without a grid is created.

0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant

@Browning_Zed wrote:

....
4. But if I run the "VPORTS" command, then the program algorithm works as it should - a viewport without a grid is created.


Then I suggest you try it [no guarantees] with the hyphen added to the new definition's command name:

  (defun C:-VPORTS ....

, and if it makes any difference, removed from inside the new definition.  [When inside an AutoLisp (command) function, it will use the command-line version rather than the dialog-box version, anyway.]

Kent Cooper, AIA
0 Likes
Message 9 of 15

Browning_Zed
Advocate
Advocate

The same. In this case, the "-VPORTS" command will not create the grid, but the "_-vports" command will still create the grid.

0 Likes
Message 10 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

This should work.

 

(command "_.UNDEFINE" "-VPORTS")

(defun c:-VPORTS (/ e)
  (setq e (entlast))
(command-s "_.-VPORTS")
  (if (not (equal e (entlast)))
    (setpropertyvalue (entlast) "GridOn" 0))
)

 

 

0 Likes
Message 11 of 15

Browning_Zed
Advocate
Advocate

Unfortunately, this did not change the situation either.😞

0 Likes
Message 12 of 15

ВeekeeCZ
Consultant
Consultant

It runs flawlessly on my side.

 

Try it separately, first undefine -vports. You might experiment and undefine _-vports as well-

Then load the custom routine. You can add there some sort of note to make sure it's running. like (princ "\nmy -vports command is running"

 

btw which version of acad you have?

 
Message 13 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

Does it work if the (setpropertyvalue) function is replaced with this?

(vla-put-GridOn (vlax-ename->vla-object (entlast)) 0)

Kent Cooper, AIA
Message 14 of 15

Browning_Zed
Advocate
Advocate
I apologize. I have AutoCAD Map 2020, and as it turned out, the code does not work on it. By running standard AutoCAD 2020, I made sure that the code works fine. I don’t know why the routine doesn’t work in Map, but the fact remains. Thanks for your help, the issue has been resolved.
0 Likes
Message 15 of 15

Browning_Zed
Advocate
Advocate

The problem was with AutoCAD Map. In standard AutoCAD, the routine works fine.

 


@Kent1Cooper  написал (-а):

(vla-put-GridOn (vlax-ename->vla-object (entlast)) 0)


This code works in AutoCAD Map 3D. Thank you so much.

0 Likes