Import postprocessing script location

fenschop
Posts: 55
Joined: 24 Jul 08 12:47

Re: Import postprocessing script location

Post by fenschop » 17 Aug 18 21:37

A lot of nice thoughts about filename conventions. Much simpler than my always slightly complicated solutions. But see it from this perspective: As a professional SW guy I don't want to feel defeated by a scripting environment in PSu4!

Also the suggestion to cast it to TImageItem does not work. It gives an access violation. I assume that in the importer it is still a different type.
PSu4-D2.png
PSu4-D2.png (12.88 KiB) Viewed 496 times
Frank

fenschop
Posts: 55
Joined: 24 Jul 08 12:47

Re: Import postprocessing script location

Post by fenschop » 17 Aug 18 23:19

The Selected.Items in the importer seem to be (childs of) TXOMObject, and the attributes are likely stored in the props array of this object as a kind of key, value pairs, of type TOMProp. On TOMProp I can't find documentation. I guessed a few fields, but the most promising appear to be empty strings.

Code: Select all

procedure Initialize;    // use this procedure for global initialization
begin
  //Say(Selected.Items[0] is TObject);
  //Say(Selected.Items[0] is TOMObject);
  Say(Selected.Items[0] is TXOMObject);  //True
  Say(TXOMObject(Selected.Items[0]).AsString); // serialized object with 13 key, value pairs
  Say(TXOMObject(Selected.Items[0]).PropCount);  //14
  Say(TXOMObject(Selected.Items[0]).GetProperty('FileName') is TOMProp); //True
  Say(TXOMObject(Selected.Items[0]).GetProperty('FileName').Name); //Empty
  Say(TXOMObject(Selected.Items[0]).GetProperty('FileName').Text); //Empty
  Say(TXOMObject(Selected.Items[0]).GetProperty('FileName').Index);  // 1111
end;
If I put an arbitrary string as key in GetProperty, it just returns a null (pointer). So I feel I am on the right track.

What is the proper way to read the value from TOMProp?
Or is there a standard way to convert a TXOMObject into for example a TImageItem?

Frank

fenschop
Posts: 55
Joined: 24 Jul 08 12:47

Re: Import postprocessing script location

Post by fenschop » 20 Aug 18 7:15

I got my script running by deploying a workaround to parse the filename from the serialized object by the AsString method. See viewtopic.php?f=57&t=27263#p120460

It looks like the FileName property can't be extracted in a nice way, as the Selected.Items[j] are of a type that does not have a parent child inheritance relationship, and the actual type is not available in the scripting environment. Can this be improved in a future update?

This is the workaround:

Code: Select all

	  if (Selected.Items[0] is TImageItem) then
	  begin
		//++++Normal scripting section++++
		Image := Selected.Items[i];
	  end
	  else
	  begin
		//++++Downloader section++++
		//Parse FileName from serialized version of object of inaccessible type
		//Most likely it is a TDownloadImage
		OriginalName := TXOMObject(Selected.Items[i]).AsString;
		OriginalName := RightStr(OriginalName, Length(OriginalName)+1-Pos('XOMObject.FileName', OriginalName)-18);
		OriginalName := RightStr(OriginalName, Length(OriginalName)+1-Pos('''', OriginalName)-1);
		OriginalName := Trim(LeftStr(OriginalName, Pos('XOMObject', OriginalName)-1));
		OriginalName := LeftStr(OriginalName, Length(OriginalName)-1);
		Image := TImageItem.Create(nil);
		Image.FileName := OriginalName;
		Image.UpdateFileInfoBase();
	  end

Hert
Posts: 15909
Joined: 13 Sep 03 7:24

Re: Import postprocessing script location

Post by Hert » 20 Aug 18 8:21

That's great. And in the next update, the TDownloadImage is made available in the scripter
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

fenschop
Posts: 55
Joined: 24 Jul 08 12:47

Re: Import postprocessing script location

Post by fenschop » 20 Aug 18 8:38

Thanks! Because the workaround depends on the exact format of the Serializer behind AsString and it assumes that there is at least one more property after FileName. And of course the search strings should better not occur in filenames. TDownloadImage exported makes more robust code.

Post Reply