  
  
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Header
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  !exportname = 'Teste'
  !DateTime = 'Teste'
  !Source = 'MPMI-UFF' $* 
  !Version = 'Teste' $* Versão do PDMS
  !UserName = 'Teste'
  !Purpose = 'Teste' $* Propósito da análise
  !ProjectName = 'Teste'
  !MDBName = 'Teste'
  !TitleLine = 'Teste' $* Nome da análise
  
  
  !lines = array()
  !lines.append('<?xml version="1.0" encoding="utf-8"?>')
  !lines.append('<PipeStressExport ' + !exportname)
  !lines.append('<DateTime>' + !DateTime + '</DateTime>')
  !lines.append('<Source>' + !Source + '</Source>')
  !lines.append('<Version>' + !Version + '</Version>')
  !lines.append('<UserName>' + !UserName + '</UserName>')
  !lines.append('<Purpose>' + !Purpose + '</Purpose>')
  !lines.append('<ProjectName>' + !ProjectName + '</ProjectName>')
  !lines.append('<MDBName>' + !MDBName + '</MDBName>')
  !lines.append('<TitleLine>' + !TitleLine + '</TitleLine>')
  
  
  
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Units
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  !DistanceUnits = 'MM'
  !BoreUnits = 'MM'
  !PressureUnits = 'BAR G'
  !TemperatureUnits = 'C'
  !WeightUnits = 'kg'
  !ForceUnits = 'N.'
  !WallThicknessUnits = 'mm'
  !FluidDensityUnits = 'kg./cu.m'
  
  !lines.append('<Units>')
  
  !lines.append('<DistanceUnits>' + !DistanceUnits + '</DistanceUnits>')
  !lines.append('<BoreUnits>' + !BoreUnits + '</BoreUnits>')
  !lines.append('<PressureUnits>' + !PressureUnits + '</PressureUnits>')
  !lines.append('<TemperatureUnits>' + !TemperatureUnits + '</TemperatureUnits>')
  !lines.append('<WeightUnits>' + !WeightUnits + '</WeightUnits>')
  !lines.append('<ForceUnits>' + !ForceUnits + '</ForceUnits>')
  !lines.append('<WallThicknessUnits>' + !WallThicknessUnits + '</WallThicknessUnits>')
  !lines.append('<FluidDensityUnits>' + !FluidDensityUnits + '</FluidDensityUnits>')
  
  !lines.append('</Units>')
  
  
  
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Exportação
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  !pipes = !!collectallfor('pipe','',!!ce)
  
  !nodenumberInt = 0
  
  -------------------------------------------------------------
  -- Dados das linhas
  -------------------------------------------------------------
  do !pipe values !pipes
    
    !FullName = !pipe.fullname
    !Ref = !pipe.dbref.string()
    
    !lines.append('<Pipe>')
    !lines.append('<FullName>' + !FullName + '</FullName>')
    !lines.append('<Ref>' + !Ref + '</Ref>')
    
    
    -------------------------------------------------------------
    -- Dados dos branches
    -------------------------------------------------------------
    !branches = !!collectallfor('bran','',!!ce)
    
    do !bran values !branches
      
      !lines.append('<Branch>')
      
      !Branchname = !bran.fullname
      !lines.append('<Branchname>' + !Branchname + '</Branchname>')
      
      !Temperature1 = !bran.temp.string()
      !Temperature2 = '-10000'
      !Temperature3 = '-10000'
      !Temperature4 = '-10000'
      !Temperature5 = '-10000'
      !Temperature6 = '-10000'
      !Temperature7 = '-10000'
      !Temperature8 = '-10000'
      !Temperature9 = '-10000'
      !lines.append('<Temperature>')
      !lines.append('<Temperature1>' + !Temperature1 + '</Temperature1>')
      !lines.append('<Temperature2>' + !Temperature2 + '</Temperature2>')
      !lines.append('<Temperature3>' + !Temperature3 + '</Temperature3>')
      !lines.append('<Temperature4>' + !Temperature4 + '</Temperature4>')
      !lines.append('<Temperature5>' + !Temperature5 + '</Temperature5>')
      !lines.append('<Temperature6>' + !Temperature6 + '</Temperature6>')
      !lines.append('<Temperature7>' + !Temperature7 + '</Temperature7>')
      !lines.append('<Temperature8>' + !Temperature8 + '</Temperature8>')
      !lines.append('<Temperature9>' + !Temperature9 + '</Temperature9>')
      !lines.append('</Temperature>')
      
      !Pressure1 = !bran.pres.string()
      !Pressure2 = '0'
      !Pressure3 = '0'
      !Pressure4 = '0'
      !Pressure5 = '0'
      !Pressure6 = '0'
      !Pressure7 = '0'
      !Pressure8 = '0'
      !Pressure9 = '0'
      !lines.append('<Pressure>')
      !lines.append('<Pressure1>' + !Pressure1 + '</Pressure1>')
      !lines.append('<Pressure2>' + !Pressure2 + '</Pressure2>')
      !lines.append('<Pressure3>' + !Pressure3 + '</Pressure3>')
      !lines.append('<Pressure4>' + !Pressure4 + '</Pressure4>')
      !lines.append('<Pressure5>' + !Pressure5 + '</Pressure5>')
      !lines.append('<Pressure6>' + !Pressure6 + '</Pressure6>')
      !lines.append('<Pressure7>' + !Pressure7 + '</Pressure7>')
      !lines.append('<Pressure8>' + !Pressure8 + '</Pressure8>')
      !lines.append('<Pressure9>' + !Pressure9 + '</Pressure9>')
      !lines.append('</Pressure>')
      
      -- O PSI possui uma UDA nos materiais no catálogo. Deve ser preenchido nos outros projetos ou deve ser criada uma tabela
      !MaterialNumber = string(:matnum of matxt of spref of hstu of $!bran)
      !lines.append('<MaterialNumber>' + !MaterialNumber + '</MaterialNumber>')
      
      
      handle (2,114) $*  =0/0 has no attribute
      elsehandle any
      elsehandle none
        !lines.append('<InsulationDensity>' + !InsulationDensity + '</InsulationDensity>')
      endhandle
      
      !FluidDensity = string(Density of sden1 of tden1 of flure of pspec of $!bran)
      !lines.append('<FluidDensity>' + !FluidDensity + '</FluidDensity>')
      
      
      -------------------------------------------------------------
      -- Dados dos componentes
      -------------------------------------------------------------
      !comps = !!collectallfor('bran memb','',!!ce)
      
      do !component values !comps
        
        !lines.append('<Node>')
        
        !nodenumberInt = !nodenumberInt + 1
        !NodeNumber = !nodenumberInt.string()
        !lines.append('<NodeNumber>' + !NodeNumber + '</NodeNumber>')
        
        -- estamos exportando apenas o pa
        !Endpoint = '1' $* 0 = origin, 1 = pa, 2 = pl (for bran 1 = ph, 2 = pt)
        !lines.append('<Endpoint>' + !Endpoint + '</Endpoint>')
        
        $(
        !Rigid = 'asd'
        !lines.append('<Rigid>' + !Rigid + '</Rigid>')
        $)
        
        !ComponentType = !component.type
        !lines.append('<ComponentType>' + !ComponentType + '</ComponentType>')
        
        !Weight = !component.brwei.string()
        handle (2,245) $*  Attribute BRWEIG cannot be calculated for element INSTRUMENT /FE-116. Attribute CMPR of SPCOMPONENT /A300/A0IQBD0:100 not set or wrong for INSTRUMENT /FE-116.
        elsehandle any
        elsehandle none
          !lines.append('<Weight>' + !Weight + '</Weight>')
        endhandle
        
        !componentRefNo = !component.ref.string()
        !lines.append('<componentRefNo>' + !componentRefNo + '</componentRefNo>')
        
        !OutsideDiameter = !component.aod.string()
        handle (2,201) $*  Element BRANCH /100-B-1-B2 does not have attribute AOD
        elsehandle any
        elsehandle none
          !lines.append('<OutsideDiameter>' + !OutsideDiameter + '</OutsideDiameter>')
        endhandle
        
        $(
        !WallThickness = string(:cwall of cmpref of spref of $!component) $* Pegar do codtub ou criar UDA no cmpref ou spref
        !lines.append('<WallThickness>' + !WallThickness + '</WallThickness>')
        handle any
          !cn = !component.fullname
          $P $!cn
        endhandle
        $)
        
        !CorrosionAllowance = 'Criar UDA no catálogo'
        !lines.append('<CorrosionAllowance>' + !CorrosionAllowance + '</CorrosionAllowance>')
        
        if !component.type eq 'REDU' then
          !AlphaAngle = string(atan(( abs(!component.aod - !component.lod) / 2 ) / (0.6 * !component.apos.distance(!component.lpos))))
          !lines.append('<AlphaAngle>' + !AlphaAngle + '</AlphaAngle>')
        endif
        
        !InsulationThickness = !component.inth.string()
        !lines.append('<InsulationThickness>' + !InsulationThickness + '</InsulationThickness>')
        
        !Position = !component.e.string() + ' ' + !component.n.string() + ' ' + !component.u.string()
        !lines.append('<Position>' + !Position + '</Position>')
        
        !BendRadius = string(tan( !component.adir.angle(!component.ldir) / 2 ) * !component.apos.distance(!component.pos))
        handle (2,201) $*  Element TEE 1 of BRANCH /250-B-50/B1 does not have attribute LDIR
          
        elsehandle none
          !lines.append('<BendRadius>' + !BendRadius + '</BendRadius>')
        endhandle
        
        $(
        !BendType = !component
        !lines.append('<BendType>' + !BendType + '</BendType>')
        $)
        
        !SIF = string(rating of cate of catref of $!component)
        !lines.append('<SIF>' + !SIF + '</SIF>')
        
        
        
        -------------------------------------------------------------
        -- Dados dos suportes
        -------------------------------------------------------------
        if !component.type eq 'ATTA' then
          --se for suporte, ou seja, se tiver geometria
          !isSupport = true
          if !isSupport then
            
            !lines.append('<Restraint>')
            
            !Type = !component.:NodeType.string()
            !lines.append('<Type>' + !Type + '</Type>')
            
            !Stiffness = !component.:Nodestiff.string()
            !lines.append('<Stiffness>' + !Stiffness + '</Stiffness>')
            
            !Gap = !component.:Nodegap.string()
            !lines.append('<Gap>' + !Gap + '</Gap>')
            
            !Friction = !component.:NodeFriction.string()
            !lines.append('<Friction>' + !Friction + '</Friction>')
            
            !lines.append('</Restraint>')
            
          endif
        endif
        
        !lines.append('</Node>')
        
      enddo
      
      !lines.append('</Branch>')
      
    enddo
    
    !lines.append('</Pipe>')
    
  enddo
  
  !lines.append('</PipeStressExport>')
  
  
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  -- Fim da exportação, cria o arquivo
  ------------------------------------------------------------------------------
  ------------------------------------------------------------------------------
  !file = object file('c:\aveva\pipingflexibilitypdms2xml.xml')
  !file.writefile('over',!lines)
  !filename = !file.fullname()
  
  !!alert.message('Arquivo
$!filename
Criado')
  
  
