Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maxscript to Photoshop: Can't find correct argument for Selection.Select()

Maxscript to Photoshop: Can't find correct argument for Selection.Select()

TurboChiken
Contributor Contributor
151 Views
2 Replies
Message 1 of 3

Maxscript to Photoshop: Can't find correct argument for Selection.Select()

TurboChiken
Contributor
Contributor

I'm learning to manipulate Photoshop through Maxscript, and I'm just trying to select a specific area of the Photoshop document using [document].Selection.Select [region]. But I can't figure out how to pass the [region] argument, everything I try kicks an error of some kind. Does anyone have experience with this?

 

ps = CreateOLEObject"Photoshop.Application" -- launches Photoshop
doc = ps.application.documents.add 200 200 -- create a new document, 200 by 200 pixels
doc.Selection.Select #(0, 0, 100, 100) -- attempt to select an area, but it kicks an error
0 Likes
152 Views
2 Replies
Replies (2)
Message 2 of 3

A娘
Advocate
Advocate

if the area was empty ,select was forbidden

0 Likes
Message 3 of 3

TurboChiken
Contributor
Contributor

I wasn't able to get .select() to work, but I was able to write a workaround function by selecting the entire canvas, scaling the selection down to the correct size, and then translating it as needed:

-- Given a document reference, this selects the given area. x1 and y1 are the top left, and x2 and y2 are the bottom right.
-- Couldn't figure out how to use the .select() command, so we're using a workaround by selecting everything, then resizing and translating.
fn selectArea doc x1 y1 x2 y2 = (	
	
	doc.selection.selectAll()
	local arr=doc.selection.bounds.dataArray
	local currWidth=arr[3]-arr[1], currHeight=arr[4]-arr[2]	
	local newWidth=x2-x1, newHeight=y2-y1	
	local scaleX=newWidth/currWidth*100, scaleY=newHeight/currHeight*100

	doc.selection.resizeBoundary (scaleX) (scaleY) 1 -- 1 means anchored in top left
	doc.selection.translateBoundary x1 y1	
)
0 Likes