Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ImportInstance Geometry vs get_Geometry

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
michellem
423 Views, 3 Replies

ImportInstance Geometry vs get_Geometry

Hello Everyone;

 

I am working thru some sample code that is meant to get the geometry from an Autocad import instance and I have a question about the get_Geometry call shown below:

 

 

 

 Reference r = uidoc.Selection.PickObject( 
      ObjectType.Element,
      new JtElementsOfClassSelectionFilter<ImportInstance>() );

    var import = doc.GetElement( r ) as ImportInstance;

    // Get Geometry

    var ge = import.get_Geometry( new Options() );

    foreach( var go in ge )
    {
      if( go is GeometryInstance )
      {
        var gi = go as GeometryInstance;

        var ge2 = gi.GetInstanceGeometry();

        if( ge2 != null )

 

 

 Retrieve Visible dwg geometry Link 

 

My understanding is that the code gets an ImportInstance and the calls get_Geometry to get the geometry. However, when I look at the Revit API docs for this object I see only a Geometry property but not a get_Geometry property or method. Shouldn't the code call the Geometry property since that is what the API says is available? What am I missing? (I am trying to convert the code to Python.) ( Revit API link  )

 

Also when I am working in the Revit Pyhon Shell app, the autocomplete shows that the Geometry property is available for use but not get_Geometry. If I try to use the Geometry property I get an error but if I try get_Geometry things work. So why is get_Geometry not listed? And why does Geometry returns an error? (TypeError: indexer# is not callable).

 

Sincerely;

Michelle

 

3 REPLIES 3
Message 2 of 4
architect.bim
in reply to: michellem

Hi!

I you look into the documentation you can see that Geometry is actually an indexer. To get its value you need to specify the index in square brackets:

# Python sample
geometry = import.Geometry[Options()]

But also any property, including the indexer, can be replaced by a method with a get prefix. In this case, the value is passed in parentheses, not square brackets. This is not mentioned in the Revit API documentation as it is the basic syntax of IronPython and C# languages.

# Python sample
geometry = import.get_Geometry(Options())

Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 3 of 4
michellem
in reply to: architect.bim

Hello Maxim;

 

Thank you for the response and for including the link to Indexers. So after reading the material on Indexers, I see that it is the word "this" (and maybe the square brackets) in the Revit API that indicates that ImportInstance.Geometry is an indexer. Since I don't know C# and barely remember the original C language, it was certainly something that flew over my head.

public GeometryElement this[
	Options options
] { get; }

 

Is it correct to say, the statement y = ImportInstance.Geometry[Options()] returns a value based on the index presented by Options()? Put another way, if I had bucket of misc fruit with an indexer attached to it and wrote y =  FruitBucket["apple"], the indexer would return an object associated with index of "apple" - that is an Apple object.

 

Also, if there is a "get_" prefix would there also be a "set_" prefix in IronPython?

Finally, would anyone know of a good book, or online link, that would discuss this "_get" prefix in more detail? I tried to Google it and had no luck.

Michelle

 

 

Message 4 of 4
jeremy_tammik
in reply to: michellem

Here is a nice little booklet on the topic for you to print at your leisure:

  

https://duckduckgo.com/?q=.net+get_+property+prefix

  

🙂

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report