Electronic – How to change the project parameters in Altium Designer with a Delphi Script

altiumscript

How can I change the project parameters in Altium Designer with a Delphi Script. I already found a script on how to change the Sheet Parameter, but I really need to change the Project Parameters.

Best Answer

Here's how I do it:

procedure SetProjectParameter(ParamName,ParamValue : String);
var
  Project       : IProject;
  Parameter     : IParameter;
  i             : Integer;
  notfound      : boolean;
begin
  Project := GetWorkspace.DM_FocusedProject;
  If Project = Nil Then Exit;
  notfound:=True;
  If Project.DM_ParameterCount >0 then
  begin
    for i:=0 to Project.DM_ParameterCount-1 do
    begin
      if Project.DM_Parameters(i).DM_Name = ParamName then
      begin
        Parameter:=Project.DM_Parameters(i);
        if Parameter.DM_Value  ParamValue then Parameter.DM_SetValue(ParamValue);
        notfound:=False;
      end;
    end;
  end;
  if notfound=True then // if parameter not found, create a new one
  begin
    Parameter:=Project.DM_AddParameter(ParamName,ParamValue);
  end;
end;