Monday, January 05, 2009

*Warning* Multiply owned object, handle "17B7"

Sometimes an error message pops up in Civil 3D that gives you a warning that multiply owned objects are in the drawing. There is a nifty Lisp routine that has been going around that lets you delete the object. The object in question may be created when a child label is dragged to another drawing that already has the parent style in it. The Lisp does delete the object in question, but what if you want to know what type of object it is before deleting it? Well this post will show a way to figure out what the object is and then let you decide if you want to delete it.

We'll do this in VBA, though I'm sure you could do this in Lisp. First type VBAMAN at the command line and then choose the New button on the right side of the dialog box and then do a SaveAs to save it in a location you can remember.


Next type you can choose to type Option Explicit at the top of the blank page or you can skip it. Then Type Sub and what you want to call the routine, in this case I choose what my daughter's say cow's say. Then add "On Error Resume Next", this line will have the program continue if an error message is occurs in VBA. It is usually better to use better error catching, but it should OK for this program.

Next declare the variables that are going to be used. In this case sHandle as a string for the object's handle, oTempObject to convert the handle to an AutoCAD object and Response as a generic variable to catch the value the user selects in the MsgBox that will be created later on.

So now we have the base done we can get the handle from the user using the GetString method.

sHandle = ThisDrawing.Utility.GetString(0, "Enter String: ")

The user can copy and paste the handles from the command line to the command line. Now we need to make sure the user typed something so we need to check. If the user hasn't typed anything in we'll just assume they don't want to run it and exit the sub.

If sHandle = "" Then

Exit Sub

End If

Next we'll need to convert the handle into an AutoCAD object using the HandleToObject method.

Set oTempObject = ThisDrawing.HandleToObject(sHandle)

So hopefully the user entered a valid handle, if not it just asks them for a new handle because of a line at the end of the code and the On error Resume Next line of code. So then we may send a message box up and tell the user what type of object it is and ask if they want to delete it.

Response = MsgBox("The object is a " & oTempObject.ObjectName & " Do you want to delete the object?", vbYesNo)

If the user selects Yes, the object will be deleted, if not nothing will happen to the object.

If Response = vbYes Then
End If

There are usually more than one MOO, so we'll call the Moo Sub again to loop around until the user doesn't enter a value for the handle.

Call Moo

In my test drawing the object type was AeccDbLabelStyleText object it could be something different for you, but now you'll know what type of object it is before deleting it. The completed dvb file may be found on this page.


Lisa Pohlmeyer said...

Great tip Chris, thanks. I just want to let you know I appreciate your blog & programming efforts. Happy New Year!

Anonymous said...

Thanks. Needed this information right now.


Blog Widget by LinkWithin