[Ir...] Posted September 24 Share Posted September 24 Hello, I would like to know how to create a duplicate of an element (copy and paste) and specify the name of the duplicate before it is created. Whether you do it manually or automatically via a script, as soon as you paste the item, the program names it as “ELEMENT NAME Copy 1” or “ELEMENT NAME Copy 2” if the first name is already taken. Additionally, “Copy 1” could be “Copiar 1” or another equivalent depending on the language settings. When you do it manually, you can easily change the name after pasting because you can see exactly what the element is. However, the problem arises when I want to automate a copy-paste operation in a script. Currently, this is what I do: As you can see, I use conditionals to obtain the word that the program uses to create duplicates (lines 1008-1019). Then, I predict the name that the software will use when the element is pasted (line 1023). After that, I perform the Copy and Paste operations (lines 1027-1031). Finally, I rename the element. This works as long as there is no other element with the name nge_copia. That is why I wonder if there is any part of the code I could use to decide the name of the pasted element. If not, I would need a code to check if an element named nge_copia already exists. Link to comment Share on other sites More sharing options...
[Ma...] Posted September 24 Share Posted September 24 Hello, Maybe that'll help: When you paste items from the clipboard, it is possible to get the names of the inserted items. elements = gom.script.sys.paste_from_clipboard (destination=[]) print(elements) Link to comment Share on other sites More sharing options...
[Ja...] Posted September 25 Share Posted September 25 Can i ask what your end goal is by copying elements in this way? There may be other methods to acheieve your end goals. Link to comment Share on other sites More sharing options...
[Ir...] Posted September 25 Author Share Posted September 25 Thank you Marcus! Regarding your question, James, the goal of copying elements is to use an inspection element from one item in another item with exactly the same tolerances and settings, without deleting the inspection of the initial element. For example, if I want to apply the same inspection of a cylinder to a circle using the same exact settings (as shown in the image above), my script would do this by creating a duplicate of the cylinder and assigning its diameter to the circle by editing the creation parameters. These steps are illustrated in the image below. After this process, the duplicate would be erased, as it is only used as an auxiliary element. The reason I do it this way is that it can be applied to any inspection element without having to extract all the creation parameters (which are different for each inspection element). Link to comment Share on other sites More sharing options...
[Ir...] Posted September 25 Author Share Posted September 25 Please sign in to view this quote. I've been trying this method, but the variable "elements" I get is an array, such as these: [gom.app.project.inspection['Cylinder 1 Copy 3'], gom.app.project.nominal_elements['Cylinder 1 Copy 3'], gom.app.project.inspection['Feature Control Frame (139) "CN027" Copy 3'], gom.app.project.inspection['Cylindrical Dimension (127) "CN028" Copy 3']] [gom.app.project.nominal_elements['Cylinder 1 Copy 4'], gom.app.project.inspection['Cylinder 1 Copy 4'], gom.app.project.inspection['Feature Control Frame (139) "CN027" Copy 4'], gom.app.project.inspection['Cylindrical Dimension (127) "CN028" Copy 4']] The items that appear on these lists are all the elements pasted, not only the cylinder (in this case), but also all the realated inspections. The elements I need to track from the arrays are "gom.app.project.inspection['Cylinder 1 Copy 3']" in the first case and "gom.app.project.inspection['Cylinder 1 Copy 4']" in the second. However, these elements are not always in the same position within the array. I don’t know why this happens or what I can do to obtain the elements I want. Link to comment Share on other sites More sharing options...
[Ma...] Posted September 25 Share Posted September 25 There are several options for this. One of them would be: gom.script.sys.copy_to_clipboard (elements=[nge]) gom.script.cad.edit_tags ( add_tags=['TEST'], elements=[nge]) elements = gom.script.sys.paste_from_clipboard (destination=[]) for e in elements: if 'TEST' in e.tags: print(e) Link to comment Share on other sites More sharing options...
[Ir...] Posted September 25 Author Share Posted September 25 Thank you Marcus! It has been very helpful! Link to comment Share on other sites More sharing options...
[Ma...] Posted September 26 Share Posted September 26 (edited) Hi, maybe you can also use one of the methods described in Selecting elements in scripts — Add-On Documentation (zeissiqs.github.io). If you know an element's name (or part of it), you can apply the Explorer filter. This way you can also test if an element with the specified name already exists. Best regards, Matthias Edited September 26 Link to comment Share on other sites More sharing options...
[Ja...] Posted September 26 Share Posted September 26 Im afraid i dont quite follow...it looks like you have a goal of applying the same checks and measuring principle from say cylinder a to cylinder b ? If thats the case id suggest looking into user defined inspection principles as these will store all relevant parameters . I.e. Create cylinder, apply meas principle fitting cylinder , apply check a , b ,c with tolerance 1,2,3 , click on nominal cylinder and create user defined principle. Click on another nominal cyliner with nothing applied yet and there will be an option to apply this principle that will replay all child items stored in the principle you saved. Does this help? Link to comment Share on other sites More sharing options...
[Ir...] Posted October 3 Author Share Posted October 3 That's right, James, my goal is to apply the same inspections from one element to another. I know that I can access all the relevant parameters of each check in the script, but I would have to store the necessary parameters for each check to recreate the same check in another element. For example, if we have a position inspection, I need the tolerance, the datum, material condition, etc. However, for roundness, I would only need the tolerance. So in order to to simplify this process, I came up with the idea of duplicating “element A” (so all the inspections will be duplicated too) and then going through each check to change the element related to “element B”. This way, there is no need to obtain all the parameters of each check. Regards, Irune Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in