koenr Posted April 9 Share Posted April 9 (edited) 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 April 9 by koenr Quote Link to comment
Pat Stanford Posted April 10 Share Posted April 10 My Python is too poor to help much. Â Take a look at the post in the link below. Â For that case, Bill used a Python Class to simulate a VS Array. Â Not certain if that would work for you or not. Â Â Quote Link to comment
BillW Posted April 10 Share Posted April 10 Looks like SetObjectTags call is not implemented in Python (bug) - even though the call is available in Vectorscript. Sent DM to koenr. Quote Link to comment
koenr Posted April 10 Author Share Posted April 10 (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 April 10 by koenr 1 Quote Link to comment
Pat Stanford Posted April 10 Share Posted April 10 Formal bug files on vs.SetObjectTags. Â Maybe that will get us the magic formula to make it work or a future fix. Quote Link to comment
BillW Posted April 10 Share Posted April 10 I've just reported vs.SetObjectTags omision as a bug. Quote Link to comment
twk Posted April 11 Share Posted April 11 (edited) 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 April 11 by twk 1 Quote Link to comment
Pat Stanford Posted April 11 Share Posted April 11 @twk Thank you.  I was hoping someone with more experience than I in Python might figure out that it was a different data type needed.  I think koenr and I were trying to use lists.  I will update the Developer function reference. 1 Quote Link to comment
koenr Posted April 12 Author Share Posted April 12 @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! 😄 Quote Link to comment
koenr Posted April 12 Author Share Posted April 12 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 😉 Quote Link to comment
Recommended Posts
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.