Failed to insert code in manual sample to access tree data information.

Moderator: GiD Team

Post Reply
Hemmi
Posts: 32
Joined: Fri Nov 20, 2015 6:05 am
Location: Chiba prefecture, Japan

Failed to insert code in manual sample to access tree data information.

Post by Hemmi »

An error was generated when I changed the writing.tcl in the cmas2d_customelib problem type by inserting the sample lines of code given in the manual.

The following code is given in the customisation manual (page 42; in the "Accessing tree data information" section).
I inserted it into the writing.tcl code of the cmas2d_customlib problem type, just before the "customlib::EndWriteFile" line.

Code: Select all

    (writing.tcl code; many lines omitted!)
    customlib::WriteString "Node   Mass [gid_groups_conds::give_active_unit M]"
    customlib::WriteNodes $condition_list $condition_formats "" active
    
# The following four lines are inserted from the sample code
# found on page42 of the customization manual.
set document [$::gid_groups_conds::doc documentElement]
set xpath {/cmas2d_customlib_data/condition[@n='Point_Weight']/group[@name='Point Weight Auto1']/value[@n='Weight']}
set xml_node [$document selectNodes $xpath]
set value [get_domnode_attribute $xml_node v]

    customlib::EndWriteFile ;#finish writting
}

As shown in the figure, I encountered an error after CntlX-CntlC operation.
CntlX-CntlC-ERROR.png
CntlX-CntlC-ERROR.png (219.76 KiB) Viewed 625 times
What is wrong with me?

Am using GiD 16.0.7 on Windows11 Pro.
Attachments
writing.tcl.zip
(1.17 KiB) Downloaded 11 times
foobar.gid.zip
(9.49 KiB) Downloaded 10 times
User avatar
escolano
Posts: 1922
Joined: Sun Sep 05, 1982 10:51 pm

Re: Failed to insert code in manual sample to access tree data information.

Post by escolano »

It is a mistake of the documentation,
set xpath {/cmas2d_customlib_data/condition[@n='Point_Weight']/group[@name='Point Weight Auto1']/value[@n='Weight']}
set xml_node [$document selectNodes $xpath]
in this case the attribute of the node 'group' must be 'n', not 'name'
group[@name='Point Weight Auto1']
->
group[@n='Point Weight Auto1']
Now we have fixed this documentation:
https://gidsimulation.atlassian.net/wik ... nformation

Then $document selectNodes $xpath was not selecting any DOM node because the wrong xpath

In any case, you can always examine the current DOM to know the xpath with something like
-np- W [[$::gid_groups_conds::doc documentElement] asXML]
and you will see it as XML, this in your model:

<cmas2d_customlib_data version="1.0">
<style show_menubutton_about="0" show_menubutton_search="1"/>
<!-- units -->
<units>
<!--by now it is compulsory define this node if units are used (could be empty if defaults are enougth)-->
</units>
<container n="units" pn="Units" icon="darkorange-length-18" tree_state="close">
<value n="units_mesh" pn="Geometry units" unit_mesh_definition="1"/>
<value n="units_system" pn="Units system" units_system_definition="1">
<dependencies node="//*[@unit_definition or @unit_mesh_definition='1']" att1="change_units_system" v1="{@v}"/>
</value>
<container n="basic_units" pn="Basic units" icon="darkorange-length-18" help="Basic units to be used in the analysis.">
<value n="units_length" pn="Length" unit_definition="L"/>
<value n="units_mass" pn="Mass" unit_definition="M"/>
</container>
</container>
<!-- conditions -->
<condition n="Point_Weight" pn="Point Weight" ov="point" ovm="node" icon="darkorange-weight-18" groups_icon="yelowish-group" help="Concentrated mass" tree_state="open">
<value n="Weight" pn="Weight" v="0.0" unit_magnitude="M" units="kg" help="Specify the weight that you want to apply" state=""/>
<symbol proc="gid_groups_conds::draw_symbol_image weight-18.png" orientation="global"/>
<!-- or a more customized example implementing our own procecedure <symbol proc='Cmas2d::DrawSymbolWeigth' orientation='global'/> -->
<group n="Point Weight Auto1" ov="point" tree_state="active,open">
<value n="Weight" pn="Weight" unit_magnitude="M" help="Specify the weight that you want to apply" state="" v="0.1" units="kg" tree_state="close"/>
</group>
</condition>
<!-- properties -->
<container n="Properties" pn="Properties" icon="darkorange-shellfish-18" help="Define your materials database and apply them to the surfaces of your problem" tree_state="open">
<condition n="Shells" pn="Shells" ov="surface" ovm="element" ov_element_types="triangle" icon="darkorange-shellfish-18" groups_icon="yelowish-group" help="Select your material and the surfaces related to it" tree_state="open">
<value n="material" pn="Material" editable="0" help="Choose a material from the database" values="[Cmas2d::GetMaterialsList %W]" v="Air" state="">
<edit_command n="Edit materials" pn="Edit materials" icon="darkorange-block1.png" proc="Cmas2d::EditDatabaseListDirect %W %DICT %BC"/>
</value>
<group n="Shells Auto1" ov="surface" tree_state="open">
<value n="material" pn="Material" editable="0" help="Choose a material from the database" values="[Cmas2d::GetMaterialsList %W]" state="" v="Steel" tree_state="close"/>
</group>
</condition>
<container n="materials" pn="Materials" icon="darkorange-block1" help="Materials database" tree_state="close">
<blockdata n="material" name="Air" sequence="1" editable_name="unique" icon="darkorange-wind-sign" help="Material definition" morebutton="0">
<value n="Density" pn="Density" v="1.01" help="Superficial density assuming a thickness of 1 meter" unit_magnitude="M/L^2" units="kg/m^2"/>
</blockdata>
<blockdata n="material" name="Steel" sequence="1" editable_name="unique" icon="darkorange-bracket" help="Material definition" morebutton="0">
<value n="Density" pn="Density" v="7850" help="Superficial density assuming a thickness of 1 meter" unit_magnitude="M/L^2" units="kg/m^2"/>
</blockdata>
<blockdata n="material" name="Aluminium" sequence="1" editable_name="unique" icon="darkorange-alu" help="Material definition" morebutton="0">
<value n="Density" pn="Density" v="2650" help="Superficial density assuming a thickness of 1 meter" unit_magnitude="M/L^2" units="kg/m^2"/>
</blockdata>
</container>
</container>
<groups>
<group n="Shells Auto1" onoff="1" color="magenta" type=""/>
<group n="Point Weight Auto1" onoff="1" color="green" type=""/>
</groups>
<blockdata n="Internal data">
<value n="spd_file" v="D:/cygwin64/home/temp/foobar.gid/foobar.spd"/>
</blockdata>
<display_options frame_width="215" is_frame_open="1" view_conditions_search="0" conditions_search_values=""/>
<global_preferences>
<units>
<unit_magnitude_user_sel n="M" values="kg"/>
</units>
<tree_preferences/>
</global_preferences>
</cmas2d_customlib_data>
Post Reply