Jump to content

Recommended Posts

Hello,

I'm trying to write a script that adds a label to a vwx class but i can't seem to figure it out..
I tought an array in vectorscript was the same as a list in python?
Can someone please help me out 😄 

 

def SetTags():
	# List of tags i want to add
	l = ["Concreet"]
	
	# Handle to the vwx-class i want to add the label to
	h = vs.GetObject('00. Algmeen')
	
	# Function for setting the label
	vs.SetObjectTags(h, l)


SetTags()


# Result -> Error: Invalid callback function parameter type. Parameter index= 1 name=arrTags
	# file "<string>", line 12, in <module>
	# file "<string>", line 9, in SetTags
	# file "<string>", line 1, in <module>

 

 

This is what i have in vectorscript and this works but all my code is in python.

 

Procedure Test;
VAR		A1:			Array[1..1] of String;
		B1:			Boolean;
				
Begin
	BEGIN
		A1[1]:='Concreet';
		B1:=SetObjectTags(GetObject('00. Algemeen'), A1);
	End;
End;

Run(Test);

 

Edited by koenr
Link to comment
Posted (edited)

I found a workaround for those who also need this.
In my python script after the creation of a class i whrote the following: 

vs.DoMenuTextByName("SetLabelConcreet", 0)

 

            def createclass():
                ACTIVECLASS = vs.ActiveClass()

                vs.NameClass(self.name)

                if self.fillpattern == "EMPTY":
                    vs.SetClFPat(self.name, 0)
                elif self.fillpattern == "SOLID":
                    vs.SetClFPat(self.name, 1)
                elif self.fillpattern == "ARC":
                    hatchindex = -1 * vs.Name2Index(self.hatchname)
                    vs.SetClFPat(self.name, hatchindex)
                vs.SetClFillBack(self.name, self.fillcolor)
                vs.SetClFillFore(self.name, self.fillcolor)
                if self.penpattern == 0:
                    vs.SetClLSN(self.name, 0)
                elif self.penpattern == 2:
                    vs.SetClLSN(self.name, 2)
                elif type(self.penpattern) == str:
                    index = -1 * vs.Name2Index(self.penpattern)
                    if index != 0:
                        vs.SetClLSN(self.name, index)
                    else:
                        vs.AlertInform(
                            f"Lijnstijl `{self.penpattern}` ontbreekt in dit document.",
                            "importeer dit van een ander document of maak zelf aan.",
                            False,
                        )
                else:
                    custWarning("Lijnstijl bestaat niet.")
                vs.SetClLW(self.name, self.pensize * 40)
                vs.SetClPenBack(self.name, self.pencolor)
                vs.SetClPenFore(self.name, self.pencolor)
                vs.SetCLOpacityN(self.name, self.fillopacity, self.pennopacity)
                vs.SetClUseTextStyle(self.name, self.usetextstyle)
                vs.SetClTextStyleRef(self.name, vs.Name2Index(self.textstyle))
                _b = vs.SetClassBeginningMarker(self.name, *self.beginmarker)  # type: ignore
                _b = vs.SetClassEndMarker(self.name, *self.endmarker)  # type: ignore
                vs.SetClUseGraphic(self.name, self.usegraphics)

                vs.DoMenuTextByName("SetLabelConcreet", 0)

                vs.NameClass(ACTIVECLASS)

 

I then made a custom comand object in vectorscript and added this to my work enviroment.
 

Procedure SetLabel;
VAR		A1:			Array[1..1] of String;
		B1:			Boolean;
		H1:			Handle;
				
BEGIN
	A1[1]:='Concreet';
	H1:=GetObject(ActiveClass);
	B1:=SetObjectTags(H1, A1);
End;

Run(SetLabel);


This now runs everytime i run my script.

Edited by koenr
  • Like 1
Link to comment

this has worked for me in the past. The variable passed in must strings in a tuple, be a type <tuple>.

testing for classes, but can pass any handle that can be tagged (layer, etc):
 

def tagthis(handle, value):
	if type(value) is tuple:
		vs.SetObjectTags(handle, value)
	elif type(value) is list:
		vs.SetObjectTags(handle, tuple(value))
	elif type(value) in [str, float, int]:
		vs.SetObjectTags(handle, (str(value),))
	else:
		raise ValueError("Incorrect type for Tags : <{}>".format(type(value)))

h = vs.GetObject('TestClass')
tagthis(h, ('tag1', 'tag2'))

 

Just tested in VW2023 and VW2024, all working on this end

 

Edited by twk
  • Like 1
Link to comment
18 minutes ago, koenr said:

@twk Thank you so much!! I also tried with tuples but still got errors... Guess I still did somthing wrong then but your code works perfectly! 😄 

The thing i was doing wrong was i tried to input only 1 value wich couldn't be a tuple.
If i put an empty string as first label it works fine 😉 

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