Hi @eric.bunn,
Maybe something is wrong with the “obj_c”.
Majority of rhinocommon classes have “IsValid” property. So you can try that before adding “obj_c” to the document.
Here is all the code I am using (pasted below). In the loop you will see I am printing each object starting with id to obj_c and finally id_c. If fails after id_ c is assigned. Here are the print statements when if fails:
I’ve tracked the problem down to bad objects in Rhino. These are imported step files and when you run SelBadObjects they come up as bad. I wrapped the ObjectLayer, ObjectColor and ObjectName functions in a try and except function with except simply continuing the loop and skipping the geometry. The macro now does not crash but the bad items don’t get copied. I need to find a work around for this since I receive a fair amount of customer supplied files that usually have some issues like these.
The items I want to copy are in a group. If I use CopyObjects it works but puts the copy within the group. I want an independent copy and independent group. This code worked well for that but doesn’t work when you come across a bad object.
Thank you. We have chronic problems with this not only in Rhino but in Solidworks as well. Most of these customer supplied models come from reputable CAD packages like Solidworks , Inventor, ProE etc. It is a rarity to get geometry that comes from Rhino. Rhino will typically bring this geometry in and allow one to work with it and we do this all the time. I have to figure out a way to be able to work with this geometry, as is, unfortunately.
Hi Eric,
I would post one such model here on forum. I understand that it is confidential, but there is no other way.
Then see what users will recommend in possible fixing it.
I like the idea. I will just post the bad geometry. The geometry has naked edges. I would assume that is why it comes up bad. I did determine a work around using CopyObjects and several other functions to extract the copy from the group. I’ll post the code. I do though want to figure out if it is possible to do using the original routine.
I’ve uploaded a zipped directory with a 3dm file containing several pieces of geometry. One is a simple extrusion which I’ve labeled Good, and the other is geometry imported from a foreign CAD file by way of a step file. Probably exported from Solidworks. I’ve labeled it Bad. If you run Select Bad Objects in Rhino it comes up bad and I’ve identified that it has naked edges in it. This is a common problem in Rhino with foreign CAD Files in my experience (20+ years using Rhino).
In the same directory is a python file that, when run, works on the good object and fails on the bad object.
Looking for a way to accomplish what this macro accomplishes on the good object with the bad object. If I just simple copy the object manually it works fine. I use this geometry only for reference when building a package design for it in Rhino.
Yeah, well, that is a real mess. There are so many problem areas, there is no real way to fix it easily without rebuilding it all… If you are only needing a copy of it to reference, then you can use this to copy the object with its attributes (even if it is bad):
import rhinoscriptsyntax as rs
def CopyObjectsAndAttributes():
id_L = rs.GetObjects("Select Objects to Copy", group=True)
for source_id in id_L:
copy_id=rs.CopyObject(source_id)
rs.MatchObjectAttributes(copy_id,source_id)
CopyObjectsAndAttributes()