+ Reply to Thread
Results 1 to 4 of 4

Thread: How do I access user specified attributes, via python?

  1. #1
    Robert Hexter
    Join Date
    Mar 2012
    Posts
    78
    Points
    5
    Answers Provided
    1


    0

    Default How do I access user specified attributes, via python?

    I have added a 'userModel' attribute to my basic instance placement.cga file

    I have selected and generated buildings on my lots
    They all contain placed 'instances'

    I have selected a random lot and want to check what it is via python?

    print ce.getAttribute(ce.selection()[0], '/ce/rule/userModel')

    I get None returned, yet I can clearly see I have model instance placed in the Inspector.. and I can see the project path to it?

    Are user Attributes not accessible in this manner?

  2. #2
    Andreas Ulmer
    Join Date
    Nov 2011
    Posts
    52
    Points
    22
    Answers Provided
    4


    1

    Default Re: How do I access user specified attributes, via python?

    print ce.getAttribute(ce.selection()[0], '/ce/rule/userModel')
    This command returns the USER value of the rule attribute named userModel. (The user value is set when a rule attribute is manually set in the inspector, and is displayed bold)
    It does not return the Rule value. (The rule value is suffixed with (Rule) in the Inspector.)

    Rule values can not be queried with Python atm.

    To figure out if a rule attribute is user-set, you can query its source
    ce.getAttributeSource(ce.selection()[0],"/ce/rule/userModel")

    DEFAULT -> value is set from rule
    USER -> value is set by user


    ----------------

    Object Attributes (found the Object Atttributes pane of the Inspector) are queried without prefix:
    print ce.getAttribute(ce.selection()[0], 'myObjectAttribute')
    Last edited by andreas.ulmer; 03-05-2012 at 12:44 AM.

  3. #3
    Paul MacArthur
    Join Date
    Dec 2012
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Re: How do I access user specified attributes, via python?

    Is this still the case in CityEngine 2012.1?

    I'm trying to something similar, I have this CGA rule applied to a shape:

    Code:
    version "2012.1"
    
    attr MyAttribute    = true
    
    Lot -->
        BuildingMass
    
    LotInner -->
        BuildingMass
    
    BuildingMass -->
        extrude(20)
        Building 
    
    Building -->
        set(MyAttribute, true)
        color(1,1,0)
    Then I have generated the shape. I then have this python script to interrogate it:

    Code:
    from scripting import *
    
    ce = CE()
    
    def main():
        print
        shapes = ce.getObjectsFrom(ce.selection)
        for shape in shapes:
            print
            print shape
            print ce.getAttributeList(shape)
            print ce.getAttributeSource(shape, "/ce/rule/MyAttribute" )
            print ce.getAttribute(shape, "/ce/rule/MyAttribute" )
            
    if __name__ == '__main__':
        main()
    When I select the generated object, I get this output:
    Code:
    Shape:MyBuilding.cga:Lot
    []
    None
    None
    When I delete the generated object, and just select the lot shape, I get this output:
    Code:
    Shape
    ['/ce/name', '/ce/rule/randomSeed', '/ce/rule/ruleFile', '/ce/rule/startRule', '0streetWidth\x00', '1streetWidth\x00', '2streetWidth\x00', '3streetWidth\x00', '4streetWidth\x00', 'shapeType']
    DEFAULT
    None
    My questions is, within CE 2012.1, is there a way to mark certain geometry from CGA rules and access it from python? My end goal is to mark certain geometry and then allow my python exporter to distinguish between the different geometries so it can export them into a different model file.

  4. #4
    Robert Hexter
    Join Date
    Mar 2012
    Posts
    78
    Points
    5
    Answers Provided
    1


    0

    Default Re: How do I access user specified attributes, via python?

    This is something that you would do via the reporting mechanism.
    Then use python to process the reported data.
    Last edited by rhexter; 12-13-2012 at 03:50 PM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts