Altium Delphy Script API version dependent - Page 1
Forum section: electronics / general

author: wysi
author_rank: Newbie
timestamp: September 03, 2018, 01:51:02 pm
content: 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/DelphiScriptThe 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+ReferenceIs 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:counter := 0;condition := true;while condition Dobegin//get document of number "counter"PCBProject := Workspace.DM_Projects(counter);If (AnsiUpperCase(ExtractFileExt(PCBProject.DM_ProjectFileName)) = '.PRJPCB') thenbeginBreak; //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.beginexit;end;End;Working in Altium 18 but not in Altium 16: Write messages to the message window (shows no message in 16)Code:WS := GetWorkSpace; // obtain Workspace Manager interfaceMM := WS.DM_MessagesManager; // obtain Message Manager interfaceMM.ClearMessages; // initializeMM.BeginUpdate;// add relevant messages here using MM.AddMesssage proceduresMM.AddMessage('MessageClass 1','MessageText 1', 'Altium Designer Message','Pseudo Doc 1', '', '', 3, False);MM.EndUpdate;WS.DM_ShowMessageView; // display messagesI am looking forward to your answers.ThxSimon

author: free_electron
author_rank: Super Contributor
timestamp: October 11, 2018, 03:59:39 pm
content: DM is design manager. that is legacy from 15.xxsome of that stuff is gone.

author: Just1
author_rank: Newbie
timestamp: March 17, 2020, 08:45:31 am
content: 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.Quote from: wysi on September 03, 2018, 01:51:02 pmAltium 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 theSDK documentation, this is probably the most up-to-date documentation for extension developers.Quote from: wysi on September 03, 2018, 01:51:02 pmNo, 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:Official script examples:https://techdocs.altium.com/display/SCRT/Script+Examples+ReferenceAltium Script Central:https://github.com/mbedded-ninja/AltiumScriptCentralThe "Altium Designer add-ons" project:https://github.com/Altium-Designer-addons/scripts-librariesFinally, 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.Quote from: wysi on September 03, 2018, 01:51:02 pmCode:Set SchDoc = SchServer.GetCurrentSchDocumentSet SchDocIter = SchDoc.SchIterator_Create ' scan the document for all available objectsSchDocIter.AddFilter_ObjectSet(MkSet(eSchComponent)) ' get Sch components only, see https://techdocs.altium.com/display/SCRT1/Schematic+API+Types#TObjectId for more infoSet SchCurComponent = SchDocIter.FirstSchObjectWhile Not(SchCurComponent Is Nothing) ' loop on all components of the schematic sheetSet SchCompIter = SchCurComponent.SchIterator_Create ' scan the component for all available informationSchCompIter.AddFilter_ObjectSet(MkSet(eParameter)) ' get component parameters only, see https://techdocs.altium.com/display/SCRT1/Schematic+API+Types#TObjectId for more infoSet SchCurComponentParameter = SchCompIter.FirstSchObjectWhile Not(SchCurComponentParameter Is Nothing)' Do some stuff with the parameterShowMessage SchCurComponentParameter.Name & " = " & SchCurComponentParameter.Text ' this is just an exampleSet SchCurComponentParameter = SchCompIter.NextSchObject ' go to next parameterWEndSchDoc.SchIterator_Destroy(SchCompIter)Set SchCurComponent = SchDocIter.NextSchObject ' go to next componentWEndSchDoc.SchIterator_Destroy(SchDocIter)Quote from: wysi on September 03, 2018, 01:51:02 pmCode:GetWorkspace.DM_MessagesManager.ClearMessages ' clear previous messages to see only those which are related to the current functionGetWorkspace.DM_ShowMessageView ' show up the 'Messages' panelGetWorkspace.DM_MessagesManager.BeginUpdateGetWorkspace.DM_MessagesManager.AddMessage "", "Part '" & foo & "' has been upgraded to '" & bar & "'.", "Script: MyScriptName", GetWorkspace.DM_FocusedDocument.DM_FileName, "", "", 2, FalseGetWorkspace.DM_MessagesManager.EndUpdateThis one surely works with AD17 and AD19.I hope it would help.