Jump to content

How to script clone composition class pair


Recommended Posts

I have two classes (A and A1), and A1 is present on the block diagram of VIs within A.lvclass.

I want to clone this precisely, so that I have two new classes B and B1, with B1 appearing in the VIs of B. I don't want B using A1.

When I use the LVClassLibrary.Save A Copy method on A and A1 to create B and B1, I predictably get B using A1, and a lonely B1 with no callers.

How can I either avoid this, or fix this? I don't see a way to "replace all calls to A1 with B1" or "Replace A1.lvclass with B1.lvclass" in B. 

I briefly looked at the method LVClassLibrary.Replace Item With but I don't see how I can use it when A1 doesn't appear in B's "library view"

 

Class_cloning_issue.png

 

Note that B and B1 will later go on to be modified, so A and A1 are kinda like source templates. Ultimately there will be C and D and E, each customised slightly, but based on A.

Edited by Thoric
Link to comment
Posted (edited)

Well, so far I have one ugly workaround - clone A as B and A1 as B1 into a new folder. Programmatically create a New Project, add B and A1 (its natural dependency), find A1 and call method "Replace Item With" using path to B1, set to "Save All without Prompts", then close the Project without ever saving it.
This updates B to use B1, and seems to be the only way to get the "Replace Item With" method to work. Takes about 8 seconds though.

image.png.88ffed26e98feb063bb90ce3e6da55d7.png

I originally tried putting A and A1 into a library and cloning the library, but this didn't prevent the issue, and it also blocked access to "Replace Item With".

Edited by Thoric
Link to comment
Posted (edited)

Hi Francois - as I mentioned in my second post that didn't work for me. B referenced A1, cross-linking the two libraries, and B1 in the clone was therefore uncalled. Did I do it wrong maybe? I used the Save A Copy method on the library to achieve the clone. Do you have an alternative approach?

Edited by Thoric
Link to comment

Hi Richard, 

I was referring to the Save a Copy on a LVLIB that contains classes A and A1, instead of saving individual classes sequentially.

You'd start with Template.lvlib:A.lvclass * Template.lvlib:A1.lvclass, and end up with Clone.lvlib:A.lvclass & Clone.lvlib:A1.lvclass
Your new clone lvlib will maintain the linkage within its own namespace. It then becomes a renaming operation for the Clone.lvlib:AX.lvclass to Clone.lvlib:BX.lvclass

This only work if your template has all dependent classes in the same lvlib, hence why I called that a "special case". Your solution is more generic.
Even when I don't want the classes to end up in the same lvlib, I prefer to extract them after they have been cloned...

 

image.png.2c558af23ea148d6c64dcd4eaf9c47d1.pngimage.png.1bd3ded9cf7f73263026f9897f918f8c.png

  • Like 1
Link to comment

Thanks, but that's what I thought I'd tried and it didn't work for me. My classes are perhaps bit more complex (A is actually a child of some other parent), so I wonder if that's complicating this. Certainly the entire class heirarchy is not in the lvlib. I will give it another go though! 🙂

Link to comment
1 hour ago, Thoric said:

Thanks, but that's what I thought I'd tried and it didn't work for me. My classes are perhaps bit more complex (A is actually a child of some other parent), so I wonder if that's complicating this. Certainly the entire class heirarchy is not in the lvlib. I will give it another go though! 🙂

for what it is worth, we do this...

I have a shallow-ish hierachacy somthing like ths:

actor <-- device <-- type_of_device <-- concrete_implementation

We have some scipting code to help us make a new instance of type_of_device <-- concrete_implementation

I have a template with the last two in a .lvlib, and we clone them as needed to two brand new classes.

To further complicate, our stuff is in PPLs.

Edited by Neil Pate
  • Like 1
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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

Important Information

By using this site, you agree to our Terms of Use.