avictorgm Posted September 13, 2018 Share Posted September 13, 2018 (edited) Hello, I am kind of new on Python but not on Vectorworks. I have a custom symbol that contains 2 text labels: one contains a number like "2,43", the other is always the same text not attached to the database. I need to get read that "2,43" and later do the contrary: be able to write into the field in the symbol another number. some ideas? Edited September 14, 2018 by avictorgm Quote Link to comment
JBenghiat Posted September 14, 2018 Share Posted September 14, 2018 Your easiest approach is to link the text to a record field (see the help guide for Link Text to Record). Then, you can write a simple script using vs.SetRField and vs.GetRField to write and read the data. Quote Link to comment
avictorgm Posted September 17, 2018 Author Share Posted September 17, 2018 Thanks for the answer, Yes, it´s already done: I have a group of symbols already linked between the database and the field Deckenlast. I have found this on the web from Makro, but gave me back "0", "0" and " ", " " Some help? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - import vs hpio = vs.FSActLayer(). # this MUST give back the first element of the active layer, BUT I think is NOT. hrecdef = vs.GetParametricRecord(hpio). recname = vs.GetName(hrecdef) # Name of PIO in InfoPalette hrec = vs.GetObject(recname) fld = vs.GetFldName(hrec, 10). #. I AM NOT SURE ABOUT THIS 10 vs.AlrtDialog(vs.GetTypeN(hrecdef)) # 48. answer "0" vs.AlrtDialog(vs.GetTypeN(hrec)) # 47. answer "0" vs.AlrtDialog('Recordname:' + recname). #. answer " " vs.AlrtDialog('Default:' + vs.GetRField(hrec, recname, fld)). #. answer " " # ©MaKro - June 2018 😉 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Vectorscript Symbol read.vwx Quote Link to comment
JBenghiat Posted September 17, 2018 Share Posted September 17, 2018 The example you have is for a plug-in object. If you're just dealing with linked-record symbols, the script can be a little simpler. # This gets a "handle" — a runtime object ID — to the first selected object on the active layer. hObject = vs.FSActLayer You mentioned a group of symbols — that makes this a little more difficult, as you need to get a handle to the symbols in your first selected object. You can either get the first object in the group with vs.FInGroup(hObject) and then iterate through the group, use one of the ForEachObject routines to iterate through every object meeting your specifications, or use the "waldo" technique (there should be some posts in the archive on this) to find your place in the document. If you don't mean a literal group of symbols, then cary on. # Get the value of the field. You didn't mention the name of the record, so there is a placeholder fieldDataS = vs.GetRField( hObject, YOUR_RECORD_NAME, 'Deckenlast' ) # This always returns a string, so you need to convert it to a number ok, fieldData = vs.ValidNumStr( fieldDataS ) if not ok fieldData = 0 ValidNumStr deals well with units and separator preferences, so is going to be the most robust option versus vs.Str2Num or eval(). You may want to write your own function . def Num2Str( x ) ok, n = vs.ValisNumStr( x ) if not ok: n = 0 return n vs.SetRfield also requires a formatted string argument — use vs.Str2NumF for this Quote Link to comment
Pat Stanford Posted September 17, 2018 Share Posted September 17, 2018 @JBenghiat Joshua, Can you please also comments on the idea of not using the actual parameter records in the dialog box and rather copying the original value into a variable to use in the dialog box and then writing the value back to the parameter record after the OK button is clicked. I seem to remember that this was considered best practice, but don't have time to find the appropriate threads right now. Quote Link to comment
JBenghiat Posted September 17, 2018 Share Posted September 17, 2018 Do you mean for AlrtDialog? You should be fine entering any data here, and in fact the arguments don't need to be strings, like Message() in VS. Or are you thinking of the fact that PParamName doesn't update after SetRField( ParamName )? As we're dealing with symbols and records, that doesn't even apply here. Quote Link to comment
Peter Vandewalle Posted September 28, 2018 Share Posted September 28, 2018 To write back you can also use vs.SetRField(str(yourvalue)) str() is the Python way of turning a value into a string. Quote Link to comment
avictorgm Posted October 18, 2018 Author Share Posted October 18, 2018 thanks for the help, still don't get it. but I am not giving up. Just focus in something more urgent. Quote Link to comment
avictorgm Posted January 8, 2020 Author Share Posted January 8, 2020 At the end I GOT IT!!!! Took me a little, but after this a whole world of possibilities has opened to me! import vs #Vistor Garzon 2020 based on the work of # ©MaKro - June 2018 ;-) H1 = vs.FSActLayer() H2 = vs.ActSymDef(H1) recname = vs.GetName(H2) # Name of PIO in InfoPalette Rec_Name = vs.GetObject(recname) fld = vs.GetRField(H1,'loads-roof','Deckenlast') ##### vs.GetRField(h,'DatabankName','FieldName') vs.AlrtDialog(fld) 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.