Re: [Modeling-users] creating objects by name
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-07-08 06:27:56
|
I don't remember that this was asked before, anyhow here is the magic :) (provided that the model has already been loaded into the defaultModelSet) >>> import AuthorBooks >>> from Modeling import ClassDescription >>> cd=3DClassDescription.classDescriptionForName('Book') >>> # get the class ... cd.classForInstances()=20 <class 'Book.Book'> >>> from Modeling.EditingContext import EditingContext >>> ec=3DEditingContext() >>> # create an instance ... book=3Dcd.createInstanceWithEditingContext(ec) <Book.Book object at 0x4103158c> >>> # WARNING! it is NOT registered inside the EC ... print book.editingContext() None 2 remarks: - createInstanceWithEditingContext() completely ignores the EC, the object still need to be inserted into the EC afterwards. I need to double-check this carefully (esp. wrt DBChannel.fetchObject() if you're curious). Plus the documentation is incorrect, part of it applies to classForInstances() --esp. for the delegate part) - the real stuff (importing the correct module and class) is done by EntityClassDescription.classForEntity() -- S=E9bastien. John Lenton <jl...@gm...> wrote: > I'm certain this has been asked and answered before, but I can't find > it anywhere: how can I create an object by name? By this I mean, > instead of doing >=20 > from MyModel.Thing import Thing > a_thing =3D Thing() > ec.insert(a_thing) >=20 > what magic do I use to do >=20 > do_magic() > a_thing =3D more_magic('Thing') > ec.insert(a_thing) >=20 > ? >=20 >=20 > --=20 > John Lenton (jl...@gm...) -- Random fortune: > bash: fortune: command not found |