News: HyperSizer.com has a Community Board and Customer Support System. Submit a ticket at http://hypersizer.com/ticket

Author Topic: Creating new Materials in HS via MATLAB Script  (Read 16799 times)

Neergaard

  • Client
  • **
  • Posts: 20
    •  
Creating new Materials in HS via MATLAB Script
« on: October 15, 2014, 08:04:22 AM »
Greetings

I am trying to change the data in an existing material description card, then save it with a different name.  The tricky bit is I want to script the exercise because I have all the data in a MATLAB datastructure.  I am using MATLAB R2012b in a Windows Pro 64 bit environment. I found the MATLAB example for addressing and changing temperature-dependent materials properties in the help documentation (help/Scripting/Reference/Classes/Isotropic) :D.  I have somehow messed it up ::).
My code looks like this:
        % Check for bad path. Must be absolute.
    databasePath = handles.inputdata.Path;
    projectName = handles.inputdata.Project;
    if exist(databasePath, 'file') ~= 2
       error(['The database does not exist. ', databasePath])
    end
     
    % Launch HyperSizer.exe.
    hs = actxserver('HyperSizer.Application');
    while(hs.AutomationMode == false)
        hs = actxserver('HyperSizer.Application');
    end
 
    hs.Login('HyperSizer Admin', '');
    hs.OpenDatabase(databasePath);
 
    % Open project (if exists).
    projects = hs.Projects;
    if ~projects.Contains(projectName)
        error(['Project does not exist. ', projectName])
    end
   
    project = projects.GetProject(projectName);
   
    Mat_db = PASS.material_db.mat(1,handles.inputdata.Mat_Ix);
    FtyLV = Mat_db.Fty.v * handles.inputdata.FtyL / handles.inputdata.FtyT;
    FcyLV = Mat_db.Fcy.v * handles.inputdata.FcyL / handles.inputdata.FcyT;
    FtuLV = Mat_db.Ftu.v * handles.inputdata.FtuL / handles.inputdata.FtuT;
    % Create new material
    isotropic = hs.Isotropic.GetIsotropic('Al 2024'); %Identify existing material
    isotropic.MaterialName = handles.inputdata.name{1}; % change the name
   
    %Load data from handles.inputdata to the new material
    isotropic.Basis = handles.inputdata.allowables{1};
    isotropic.Density = handles.inputdata.density;
    isotropic.FemMaterialId = handles.inputdata.mat_num;
    isotropic.Form = handles.inputdata.form;
    isotropic.Note = [handles.inputdata.Additional_comments{1},...
        ' valid for thicknesses between ', num2str(handles.inputdata.Min_range),...
        ' and ', num2str(handles.inputdata.Max_range)];
    isotropic.Temper = handles.inputdata.temper;
    isotropic.Specification = handles.inputdata.spec;
    isotropic.ThicknessRange = handles.inputdata.Max_range;
   for ii = 1:double(isotropic.Temperatures.Count)%Num_Temps
%         isoTemp = isotropic.Temperatures(ii);
        isoTemp = get(isotropic.Temperatures, 'Item', ii);
        isoTemp.FtuL = FtuLV(ii);
   end

The important bits look like this:
     
    % Launch HyperSizer.exe.
    hs = actxserver('HyperSizer.Application');
    while(hs.AutomationMode == false)
        hs = actxserver('HyperSizer.Application');
    end

    hs.Login('HyperSizer Admin', '');
    hs.OpenDatabase(databasePath);
 
    % Create new material
    isotropic = hs.Isotropic.GetIsotropic('Al 2024'); %Identify existing material

   for ii = 1:double(isotropic.Temperatures.Count)%Num_Temps
%         isoTemp = isotropic.Temperatures(ii);
        isoTemp = get(isotropic.Temperatures, 'Item', ii);
        isoTemp.FtuL = FtuLV(ii);
    end

which is almost verbatim from the MATLAB example.  When I get to the isoTemp line, I get the following error message:
K>> isoTemp = get(isotropic.Temperatures, 'Item', i);
Error using
Interface.E8DEE168_BAF1_41A1_8297_CA2E08A2D218/get
Invoke Error: Incorrect number of arguments

On the other hand, with HyperSizer 7.0 there is a new way to invoke collection classes (help/Scripting/Release Notes/Version 7.0).  When I use that vocabulary, I have success until I proceed to the next line, where I get the following error:
K>> isoTemp.FtuL = FtuLV(ii);
No public field FtuL exists for class
Interface.E8DEE168_BAF1_41A1_8297_CA2E08A2D218.

What modifications should be made to the MATLAB example so it will run with HyperSizer 7.0.54?

Ryan

  • Administrator
  • *****
  • Posts: 145
    •  
Re: Creating new Materials in HS via MATLAB Script
« Reply #1 on: October 27, 2014, 08:27:38 AM »
Sorry for the delay in this response.

You are correct that the Item() syntax has changed in 7.0. It is now a method call instead of a property (get(), set()). That code sample is out of date.

Below is the corrected code.

Code: [Select]
% Modify FtuL of an isotropic using the material name
function ModifyIsotropicMaterial(databasePath, materialName)
   
    hs = actxserver('HyperSizer.Application');
 
    while(hs.AutomationMode == false)
        hs = actxserver('HyperSizer.Application');
    end
 
    hs.Login('HyperSizer Admin', '');
    hs.OpenDatabase(databasePath);
 
    isotropic = hs.Isotropics.GetIsotropic(materialName);
 
    for i = 1:double(isotropic.Temperatures.Count)
        isoTemp = isotropic.Temperatures.Item(i); % Item is a method call in 7.0
        isoTemp.FtuL = 25e3; % psi
    end
 
    isotropic.Save();
end

I am not sure what the subsequent error is. I've tested the updated sample code and it w. It's possible that the next line is still in an error state due to the previous line. What happens if you change the script to the new Item() syntax and re-run?