This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Create/ copy widget in visu
#1
Hi

I am creating a script for automatically creating widget in normal visu (not Mosaic) based on templates. I have stolen some ideas from this thread; https://forum.logicmachine.net/showthrea...50#pid7450

But I want to do it a little different as this rigid address structure does not suit me, and I am too lazy to create all widgets and then modify them by script. I want to let the script create everything for me.

I think I may have a plan ready, but I am missing one thing; is there a command for making a copy of a widget? I need to do that in the beginning of the script to have anything to add items to.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#2
No answer from anyone... does this mean that it is not possible?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#3
You can create a copy of plan/widget like this:
Code:
oldid = 123
item = db:getrow('SELECT * FROM visfloors WHERE id=?', oldid)
item.id = nil
db:insert('visfloors', item)
newid = db:getlastautoid()
Reply
#4
(25.10.2019, 07:03)admin Wrote: You can create a copy of plan/widget like this:
Code:
oldid = 123
item = db:getrow('SELECT * FROM visfloors WHERE id=?', oldid)
item.id = nil
db:insert('visfloors', item)
newid = db:getlastautoid()
Great!
Will try that.

OK, this part is working. But to be able to add stuff to the widget I need to enter the position of each item. I tried to log the items on a widget to see what information I couldt get. A typical object gave me;
lageWidgets 25.10.2019 10:10:14
* table:
["object"]
* number: 65794
["id"]
* number: 3
["type"]
* number: 1
["name"]
* string:
["statusobject"]
* number: 65794

But I would need to have all the properties that we find in the visu-creation interface. Is there anywhere I can read up on this to find what I am looking for?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#5
(25.10.2019, 07:42)Trond Hoyem Wrote:
(25.10.2019, 07:03)admin Wrote: You can create a copy of plan/widget like this:
Code:
oldid = 123
item = db:getrow('SELECT * FROM visfloors WHERE id=?', oldid)
item.id = nil
db:insert('visfloors', item)
newid = db:getlastautoid()
Great!
Will try that.

OK, this part is working. But to be able to add stuff to the widget I need to enter the position of each item. I tried to log the items on a widget to see what information I couldt get. A typical object gave me;
lageWidgets 25.10.2019 10:10:14
* table:
["object"]
  * number: 65794
["id"]
  * number: 3
["type"]
  * number: 1
["name"]
  * string:
["statusobject"]
  * number: 65794

But I would need to have all the properties that we find in the visu-creation interface. Is there anywhere I can read up on this to find what I am looking for?

Never mind last post. I found it. I had some limitations in my SQL select, so without that, every parameter came in tho log.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#6
Hi

I am facing a problem here. I have created a script that is adding widgets to the visu, and adding labels and objects to the widgets based on my object list. I have done it all on an older SpaceLYnk I had in my office, and everything worked fine.

Now I have copied the script to a newer SL at a project and am running the script. But on this SL the widgets are created, but no labels or objects are added to the widgets.

To insert the widget I greate a table with all properties of the widget and then use the following;
Code:
db:insert('visfloors', widget)
widget being the table with properties. This part works.

When adding labels and objects I also create a table and add it like this;
Code:
db:insert('visobjects', element)

I have logged the tables, and they have the right values as far as I can see, but the elements are not added to the database. Has there been a change in this for the newer HW version. I am running FW 2.3.0 on both the new and the old SL that I have tested the script.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#7
Have you assigned floor value for elements to new floor id? Also try logging return values of insert statement, it might show where the error is.
Reply
#8
(25.11.2019, 14:29)admin Wrote: Have you assigned floor value for elements to new floor id? Also try logging return values of insert statement, it might show where the error is.

Yes, when I log the table, I have floor value, but when I log the visobjects with last floor value, the table is empty.

One other thing I can see; when I create the table I have a line stating element.id = nil to get an automatic ID, but when I log the table this line is not included. Maybe this is the problem? I should maybe get a line in the table like:
[id]
   * nil

(25.11.2019, 14:29)admin Wrote: Have you assigned floor value for elements to new floor id? Also try logging return values of insert statement, it might show where the error is.

I tested the logging of the last entered element in the old and the new SL, and in the old one I get a table in return, but not in the new one.

The script is copied from the old to the new.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#9
Do this, it will return an error if something is wrong:

Code:
res, err = db:insert('visobjects', element)
log(res, err)

As for nil keys: setting table key to nil deletes the key, accessing non-existing keys return nil.
Reply
#10
(25.11.2019, 15:12)admin Wrote: Do this, it will return an error if something is wrong:

Code:
res, err = db:insert('visobjects', element)
log(res, err)

As for nil keys: setting table key to nil deletes the key, accessing non-existing keys return nil.

OK, this did it. In my table I had a line for PIN code, and apparantly that is no longer a coloumn in the Visobjects table. It did work on the old HW, but not the new one. Has this changed in a way?

I removed the line with PIN code as I am not using it anyway, so now the script works.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#11
You've got it mixed up, pincode column was added recently not removed.
Reply
#12
(25.11.2019, 15:29)admin Wrote: You've got it mixed up, pincode column was added recently not removed.

Strange... The script worked in the old version, but not in the new one....
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#13
What error were you getting exactly?
Reply
#14
The error code was
* arg: 1
* nil
* arg: 2
* string: LuaSQL: table visobjects has no column named pincode
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Forum Jump: