Jump to content

New classes disappear from existing viewports


WhoCanDo

Recommended Posts

I have customers that, annoyingly, send me jigsaw pieces of their product.

 

I will re-draw these pieces on design layers and then create viewports of each piece so I can arrange them and fit them together to see what it looks like completed.

 

Next I will add a class to each of the components for parts lists. The reason for the completed viewport view is so I can add classes in some sort of regular alpha-numeric flow (eg. left to right).

 

However, after adding classes, it seems that the default for the viewport class list is "Invisible".

 

I know that this visibility choice can be made by manually creating a new class, but can it be done in VS ?

Link to comment

Nice work-around Pat.

 

However, adding classes, making mistakes, going back to fix them, doing the above multiple times, I'd rather put it in the macro that assigns the classes in the first place.

 

How do you think this is achievable in a script?

 

This doesn't work ForEachObject (ClassesVisible, (Sel = True), (T = Viewport));

 

Why wouldn't it be default "Visible" ?

 

Who would want to draw something and then give it a class that is not visible on their Viewport?

 

I thought the working flow should be draw-it, class-it, remove it from Viewport if not required.

  • Like 1
Link to comment

I will try to find some time later to give you a sample script.

 

But the reasons to have classes NOT show up is just as valid.

 

If you had a drawing set with a large number of viewports and then create (or import an object with a new class), would you really want that to show up in every viewport and then have to edit it out of all (or many) of them?  Most people don't which is why the default is set to invisible in existing viewports. That way you know that you are not changing what you already have.

 

 

  • Like 2
Link to comment
13 hours ago, WhoCanDo said:

Why wouldn't it be default "Visible" ?

 

Who would want to draw something and then give it a class that is not visible on their Viewport?

 

I thought the working flow should be draw-it, class-it, remove it from Viewport if not required.

This is actually what I do as when I check my drawings prior to issue I am more likely to notice something that is in my drawing but shouldn't be, rather than notice something that should be in my drawing but isn't. :-).

 

 

 

  • Like 1
Link to comment

Interesting Boh, that's an interesting process.

 

Thanks for that.

 

Any ideas as to how to switch all classes on for all specifically named Viewports on all Sheet Layers in VS ?

 

Looping through the layers and selecting the specific Viewports is the easy bit.

 

Turning on the class visibility is the problem.

Edited by WhoCanDo
Spelling mistake
Link to comment

This script will set the visibility of all classes in all viewports to visible.  Change the criteria in the ForEachObject procedure if you only want to handle specific viewports.

 

 

Procedure AllClassVisInVP;
{November 17, 2022}
{©2022 Patrick Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}

{No Warranty Expressed of Implied. Use at your own risk.}

{Sets all classes to visible in Viewports specified by the Criteria}
{Specified in the ForEachObject PROCEDURE

{To set classes to set other visibility statuses, use the following}
{in the SetObjectVariable procedure.}
{	0	= Visible}
{	-1 	= Invisible}
{	2	= Gray}

VAR
	H1, H2			:Handle;
	S1, S2			:STRING;
	L1, L2			:LongInt;
	
Procedure Execute(Hd1:Handle);

BEGIN
	For L2 := 1 to L1 DO
		BEGIN
			SetObjectVariableInt(GetObject(Classlist(L2)),1018, 0);
		End;
	
End;	
	
	
BEGIN
	L1:=ClassNum;
	ForEachObject(Execute,((T=VIEWPORT)));
End;

Run(AllClassVisInVP);

 

Link to comment

Thanks for your time Pat.

 

So it's SetObjectVariableInt that I was missing.

 

Interestingly, when I searched through the Appendix (and tried a "Find" on the same pages) the other day, Viewport was not found.

 

I can see today that the Appendix has change it's format so I'm not sure where I ended up. Even the Hyperlink that I used has been removed.

 

Screenshot 2022-11-18 114835.jpg

Link to comment

How did you know I would get stuck Pat? 😊

 

With the following, it turns on all classes for all viewports, selected or not "Class Visibility In All Viewports - 1018 - Integer - VS:SetObjectVariableInt"

 

I just want Selected Viewports (if not named TB) to have all classes on.

 

Selected Viewports are critical because if I have edited the class list for a specific Viewport then I won't select it for this script.

 

procedure ClassOn;

procedure Set_Class_On (h : handle);
var i : integer;
begin
if (Pos ('TB', GetName (h)) > 0) then begin end
else for i := 1 to ClassNum do SetObjectVariableInt (GetObject (ClassList (i)), 1018, 0);
end;

begin
ForEachObject (Set_Class_On, ((Sel = True) & (T = Viewport)));
end;
run (ClassOn);

 

 

Link to comment

We have all gotten stuck and continue to get stuck. Welcome to the Guild of VW scripters.  We are happy to support each other. Pay it forward when you can. 👍

 

 

 

Your problem is that Criteria are case sensitive.

 

Here is my version that appears to work, including some debugging code (N1 counter for how many objects selected by FOR Each Object, AlrtDialog for name of each object as it is handled, message of number of objects handled at end [including the date so you can see if the script actually ran and that you are not seeing the return from a previous run]).

 

procedure ClassOn;

Var N1:Integer;

procedure Set_Class_On (h : handle);
var i : integer;
begin
AlrtDialog(GetName(h));
if (Pos ('TB', GetName (h)) > 0) then begin end
else for i := 1 to ClassNum do SetObjectVariableInt (GetObject (ClassList (i)), 1018, 0);
N1:=N1+1;
end;

begin
N1:=0;
ForEachObject (Set_Class_On, (((T=VIEWPORT) & (SEL=TRUE))));
Message(Date(2,2),'  ',N1);
end;
run (ClassOn);

 

Link to comment

OK.  My mistake in the previous version.  The SetObjectVariableInt(1018) actually does EXACTLY what the definition in the Vectorscript Appendix says it does.

 

"Class Visibility In All Viewports". It sets the visibility of the Class handle that you pass to it the same in EVERY viewport.

 

What we really wanted was SetVPClassVisibility. You give it handle to the VP you want to change the visibility for, the name of the Class, and the visibility status you want.  Since it is a Function, I had to define a Boolean variable to take the output of the function.

 

Sorry about leading you down the wrong path.

 

 

procedure ClassOn;

Var N1:Integer;

procedure Set_Class_On (h : handle);
var i : integer;
	B1: boolean;
begin
AlrtDialog(GetName(h));
if (Pos ('TB', GetName (h)) > 0) then begin end
else for i := 1 to ClassNum do B1:=SetVPClassVisibility(h, Classlist(i),0);
N1:=N1+1;
end;

begin
N1:=0;
ForEachObject (Set_Class_On, (((T=VIEWPORT) & (SEL=TRUE))));
Message(Date(2,2),'  ',N1);
end;
run (ClassOn);

 

Link to comment

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