Author Topic: Altium Delphy Script API version dependent  (Read 3124 times)

0 Members and 1 Guest are viewing this topic.

Offline wysiTopic starter

  • Newbie
  • Posts: 1
  • Country: ch
Altium Delphy Script API version dependent
« on: September 03, 2018, 01:51:02 pm »
I am working one day with the Altium Delphy Script Interface - Its a f***** crap!

Does some one know, where I could find a better documentation of the API?
https://techdocs.altium.com/display/SCRT1/DelphiScript

The Delphy Script Examples on the altium website are outdated!!!! (from 2004). And many of this scripts won't work with altium 18.
https://techdocs.altium.com/display/SCRT/Script+Examples+Reference

Is there somewhere a list of the compatibility of commands over the different altium versions?

My Task: Build a script, which iterates through all Components in Schematic and highlights all with a certain value in a certain parameter.
I have a list with options "a, b, c, 1, 2,3". Every component can have one or none of this values for the parameter "option". This is used since many years instead of variants.

This highlighting of components with a certain option should also be done in the PCB.

Open Points:
How too loop through all Schematic documents of the current Project?

How to loop through all Parts of the PCB document of the current Project?


Working in Altium 16 but not in Altium 18: search for PCB documents (DM_Projects throws error in 18, definition not found)
Code: [Select]
    counter := 0;
    condition := true;

    while condition Do
    begin
         //get document of number "counter"
         PCBProject  := Workspace.DM_Projects(counter);
         If (AnsiUpperCase(ExtractFileExt(PCBProject.DM_ProjectFileName)) = '.PRJPCB') then
         begin
           Break; //if the current document is a PCB Project, take it and break here.
         end;
         counter := counter + 1; //otherwise count up and continue this test.
         If (counter = 100) then  //if 100 tries passed and no PCB project found, exit this function.
         begin
           exit;
         end;
    End;


Working in Altium 18 but not in Altium 16: Write messages to the message window (shows no message in 16)
Code: [Select]
   WS := GetWorkSpace;           // obtain Workspace Manager interface
   MM := WS.DM_MessagesManager;  // obtain Message Manager interface

   MM.ClearMessages;             // initialize

   MM.BeginUpdate;
   // add relevant messages here using MM.AddMesssage procedures
   MM.AddMessage('MessageClass 1','MessageText 1', 'Altium Designer Message','Pseudo Doc 1', '', '', 3, False);
   MM.EndUpdate;

   WS.DM_ShowMessageView;         // display messages





I am looking forward to your answers.

Thx
Simon
« Last Edit: September 04, 2018, 06:23:55 am by wysi »
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Altium Delphy Script API version dependent
« Reply #1 on: October 11, 2018, 03:59:39 pm »
DM is design manager. that is legacy from 15.xx

some of that stuff is gone.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 
The following users thanked this post: wysi

Offline Just1

  • Newbie
  • Posts: 4
  • Country: fr
Re: Altium Delphy Script API version dependent
« Reply #2 on: March 17, 2020, 08:45:31 am »
Hello.

It has been a while since the original question has been posted, but I think this topic should be answered to help other people in your case.

Does some one know, where I could find a better documentation of the API?
https://techdocs.altium.com/display/SCRT1/DelphiScript

The Delphy Script Examples on the altium website are outdated!!!! (from 2004). And many of this scripts won't work with altium 18.
https://techdocs.altium.com/display/SCRT/Script+Examples+Reference
Altium seems to clearly lose interest in pushing the scripting system further. So the problem of the "obsolete scripts documentation" is not going to be addressed soon...
They apparently prefer to concentrate on "extensions", which are developed through the Altium Designer SDK. You should have a look at the SDK documentation, this is probably the most up-to-date documentation for extension developers.

Is there somewhere a list of the compatibility of commands over the different altium versions?
No, not really. I must admit: this is a pain to manage. If I were you, I would test my scripts with each Altium Designer version in which I want my script to work :-\ .

As far as I'm concerned, scripts from the community always helped me more than the official documentation itself.
Here are the places you should have a look at:

Finally, I strongly recommend you to read my article "Write your first script for Altium Designer". It gathers all the information for you to start in the script development world. Plus it will give you answers to some of your questions ;) .

How too loop through all Schematic documents of the current Project?
Code: [Select]
Set SchDoc = SchServer.GetCurrentSchDocument
Set SchDocIter = SchDoc.SchIterator_Create ' scan the document for all available objects
SchDocIter.AddFilter_ObjectSet(MkSet(eSchComponent)) ' get Sch components only, see [url]https://techdocs.altium.com/display/SCRT1/Schematic+API+Types#TObjectId[/url] for more info
Set SchCurComponent = SchDocIter.FirstSchObject
While Not(SchCurComponent Is Nothing) ' loop on all components of the schematic sheet
  Set SchCompIter = SchCurComponent.SchIterator_Create ' scan the component for all available information
  SchCompIter.AddFilter_ObjectSet(MkSet(eParameter)) ' get component parameters only, see [url]https://techdocs.altium.com/display/SCRT1/Schematic+API+Types#TObjectId[/url] for more info
  Set SchCurComponentParameter = SchCompIter.FirstSchObject
  While Not(SchCurComponentParameter Is Nothing)
    ' Do some stuff with the parameter
    ShowMessage SchCurComponentParameter.Name & " = " & SchCurComponentParameter.Text ' this is just an example
    Set SchCurComponentParameter = SchCompIter.NextSchObject ' go to next parameter
  WEnd
  SchDoc.SchIterator_Destroy(SchCompIter)
  Set SchCurComponent = SchDocIter.NextSchObject ' go to next component
WEnd
SchDoc.SchIterator_Destroy(SchDocIter)

[How to] write messages to the message window?
Code: [Select]
GetWorkspace.DM_MessagesManager.ClearMessages ' clear previous messages to see only those which are related to the current function
GetWorkspace.DM_ShowMessageView ' show up the 'Messages' panel
GetWorkspace.DM_MessagesManager.BeginUpdate
GetWorkspace.DM_MessagesManager.AddMessage "[Info]", "Part '" & foo & "' has been upgraded to '" & bar & "'.", "Script: MyScriptName", GetWorkspace.DM_FocusedDocument.DM_FileName, "", "", 2, False
GetWorkspace.DM_MessagesManager.EndUpdate
This one surely works with AD17 and AD19.

I hope it would help.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf