cropping multiple open documents in photoshop when making the first selection - photoshop-script

the script I am making should do this
PDF-to psd (ok)
all documents stays open (ok)
the user make a selection what defines the crop for every open documents in Photoshop (not ok)
close and save in an other folder(ok)
The idea is that we have pdf's that we wound to crop in a certain way. But next time we will have other pdfs that has to be cropped in a different way. this what I 'have got so far but it's crops the documents like a set in the parameters.
thanks
//PDFOpenOptions.jsx
var OpenAIFile = new PDFOpenOptions;
OpenAIFile.antiAlias = false;
OpenAIFile.mode = OpenDocumentMode.CMYK;
OpenAIFile.resolution = 150;
var myFolder = Folder.selectDialog("select folder");
if(myFolder != null)
{
var fileList = myFolder.getFiles(/\.(pdf)$/i);
for(var i = 0 ;i < fileList.length; i++)
{
if(fileList[i] instanceof File)
{
var doc= open(fileList[i],OpenAIFile);
}
}
};
var outputFolder = Folder.selectDialog("Dossier de destination:");
//alert(outputFolder);
if (app.documents.length > 0) {
//flatten the active document
app.activeDocument.flatten();
//jpeg options
var myJPEGOptions = new JPEGSaveOptions();
myJPEGOptions.embedColorProfile = true;
myJPEGOptions.formatOptions = FormatOptions.STANDARDBASELINE;
myJPEGOptions.matte = MatteType.WHITE;
myJPEGOptions.quality = 12;
myJPEGOptions.scans = 3;
// get documents;
var docs = app.documents;
for (var m = 0; m < app.documents.length; m++) {
app.activeDocument = docs[m];
try {
//crop 1Lsquaire-got from script lisner
var idCrop = charIDToTypeID( "Crop" );
var desc4 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idTop, idPxl, 601.000000 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idLeft, idPxl, 2068.000000 );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idBtom, idPxl, 2948.000000 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idRght, idPxl, 2918.000000 );
var idRctn = charIDToTypeID( "Rctn" );
desc4.putObject( idT, idRctn, desc5 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc4.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idtargetSize = stringIDToTypeID( "targetSize" );
desc4.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );
executeAction( idCrop, desc4, DialogModes.ALL );
//crop 1Lsquaire
//save file to folder
var myFile = new File((outputFolder ) + "/" + activeDocument.name);
app.activeDocument.saveAs(myFile, myJPEGOptions, true);
}
catch (e) {
alert ("Error the script did not execute");
}
}
while(documents.length>0){
documents[documents.length-1].close(SaveOptions.DONOTSAVECHANGES);
}
};

If I understand you correctly you can work out where the crop co-ordinates need to be and then apply them as you see fit. If you change the script-listener crop code to a function you can pass in those co-ordinates. Just add another line for the second set of crops and either save as a new script, or just comment them out
// usage:
selectRectangle(601, 2068, 2948, 2918);
cropToSelection();
// function SELECT RECTANGLE(top, left, bottom, right)
//
// Note: co-ordinates are same as script listener
// and not so human-friendly as t,l,r,b.
// --------------------------------------------------------
function selectRectangle(top, left, bottom, right)
{
// deselect EVERYTHING first
app.activeDocument.selection.deselect();
// =======================================================
var id1 = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id3 = charIDToTypeID( "Chnl" );
var id4 = charIDToTypeID( "fsel" );
ref1.putProperty( id3, id4 );
desc1.putReference( id2, ref1 );
var id5 = charIDToTypeID( "T " );
var desc2 = new ActionDescriptor();
var id6 = charIDToTypeID( "Top " );
var id7 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id6, id7, top );
var id8 = charIDToTypeID( "Left" );
var id9 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id8, id9, left );
var id10 = charIDToTypeID( "Btom" );
var id11 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id10, id11, bottom );
var id12 = charIDToTypeID( "Rght" );
var id13 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id12, id13, right );
var id16 = charIDToTypeID( "Rctn" );
desc1.putObject( id5, id16, desc2 );
executeAction( id1, desc1, DialogModes.NO );
}
function cropToSelection()
{
executeAction( charIDToTypeID( "Crop" ), new ActionDescriptor(), DialogModes.NO );
}

Related

How to apply multiple textures to GLTF models?

I tried to apply the texture to the model, but it works only in the case of a single texture. With multiple textures, the model is not displayed.
Sample code with a single texture:
loader = new THREE.GLTFLoader().setPath('models3/');
const textureLoader = new THREE.TextureLoader();
loader.load('01-Fundament-002.gltf', function (gltf) {
var model = gltf.scene;
model.traverse ( ( o ) => {
if ( o.isMesh ) {
o.material.map = textureLoader.load('models3/Beton OsnovaVRay-DiffuseShadowMap-Edit.png');
}
} );
scene.add(model);
});
Sample code with a multiple texture:
loader = new THREE.GLTFLoader().setPath('models3/');
const textureLoader = new THREE.TextureLoader();
loader.load('01-Fundament-002.gltf', function (gltf) {
var model = gltf.scene;
model.traverse ( ( o ) => {
if ( o.isMesh ) {
const materials = [
new THREE.MeshBasicMaterial({map: textureLoader.load('models3/1.png')}),
new THREE.MeshBasicMaterial({map: textureLoader.load('models3/2.png')}),
new THREE.MeshBasicMaterial({map: textureLoader.load('models3/3.png')}),
new THREE.MeshBasicMaterial({map: textureLoader.load('models3/4.png')}),
];
o.material = materials;
}
} );
scene.add(model);
});
You cannot assign an array to the material. I think you are confusing it with cube texture. This should work assuming your model is made out of 4 meshes only.
var i = 1;
loader = new THREE.GLTFLoader().setPath('models3/');
const textureLoader = new THREE.TextureLoader();
loader.load('01-Fundament-002.gltf', function (gltf) {
var model = gltf.scene;
model.traverse ( ( o ) => {
if ( o.isMesh ) {
o.material = new THREE.MeshBasicMaterial({map: textureLoader.load(`models3/${i++}.png`)});
}
});
scene.add(model);
});

Reflection between objects ( three.js & gltf2 )

Good evening. I am export two models from Blender 2.79 to three.js.
Scene: link
Shadows work. Objects reflect the world around them but do not reflect among themselves.
Scene code:
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0, -8, 2 );
// envmap
var path = '/textures/sky_glTF/pisa/'; // ADD "/"
var format = '.png';
var envMap = new THREE.CubeTextureLoader().load( [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
] );
scene = new THREE.Scene();
scene.background = envMap;
//MR - YES mirror
var loader = new THREE.GLTFLoader();
loader.load( '/gltf/1.gltf', function ( gltf ) {
gltf.scene.traverse( function ( node ) {
if ( node.isMesh || node.isLight ) node.castShadow = true;
if ( node.isMesh || node.isLight ) node.receiveShadow = true;
} );
gltf.scene.traverse( function ( child ) {
if ( child.isMesh ) {
child.material.envMap = envMap;
}
} );
gltf.scene.position.x = 0;
gltf.scene.position.y = 0;
gltf.scene.position.z = 0;
scene.add( gltf.scene );
} );
//MR - YES mirror
var loader = new THREE.GLTFLoader();
loader.load( '/gltf/2.gltf', function ( gltf2 ) {
gltf2.scene.traverse( function ( node ) {
if ( node.isMesh || node.isLight ) node.castShadow = true;
if ( node.isMesh || node.isLight ) node.receiveShadow = true;
} );
gltf2.scene.traverse( function ( child ) {
if ( child.isMesh ) {
child.material.envMap = envMap;
}
} );
gltf2.scene.position.x = 0;
gltf2.scene.position.y = 0;
gltf2.scene.position.z = 0;
scene.add( gltf2.scene );
} );
How to implement reflections between objects?
What part of the code do you still have to show for a complete answer to my question?

Camera Autorotate threejs

How can I make camera to autorotate when i hit any obstacle in threejs. I referred the following link
http://threejs.live/#/webgl_raymarching_reflect
where the rendering restarts when it hits any obstacle. I tried implementing in my project but that doesn't works. How can i implement that in my project?
My map.ts code is
private renderer: THREE.WebGLRenderer;
private camera: THREE.PerspectiveCamera;
public scene: THREE.Scene;
public fieldOfView: number = 10;
public nearClippingPane: number = 1;
public farClippingPane: number = 1000;
public controls: THREE.OrbitControls;
#ViewChild('canvas')
private canvasRef: ElementRef;
constructor(public loadingCtrl: LoadingController) {
this.render = this.render.bind(this);
this.onModelLoadingCompleted = this.onModelLoadingCompleted.bind(this);
}
private get canvas(): HTMLCanvasElement {
return this.canvasRef.nativeElement;
}
private createScene() {
this.scene = new THREE.Scene();
var loader = new THREE.ColladaLoader();
loader.load('assets/Buildings/Block.DAE', this.onModelLoadingCompleted);
}
private onModelLoadingCompleted(collada) {
const loading = this.loadingCtrl.create({
content:'Loading Please Wait...'
});
loading.present();
var modelScene = collada.scene;
modelScene.rotation.x = -0.01 * Math.PI;
// modelScene.rotation.z = 0.03 * Math.PI;
this.scene.add(modelScene);
loading.dismiss();
this.render();
}
private createCamera() {
let aspectRatio = this.getAspectRatio();
this.camera = new THREE.PerspectiveCamera(
this.fieldOfView,
aspectRatio,
this.nearClippingPane,
this.farClippingPane
);
// Set position and look at
this.camera.position.x = 1;
this.camera.position.y = 0.4;
this.camera.position.z = 16;
}
private createLight(){
var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
this.scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
directionalLight.position.set( 1, 1, 0 ).normalize();
this.scene.add( directionalLight );
}
private getAspectRatio(): number {
let height = this.canvas.clientHeight;
if (height === 0) {
return 0;
}
this.canvas.style.width = "100%";
this.canvas.style.height = "100%";
return this.canvas.clientWidth / this.canvas.clientHeight;
}
private startRendering() {
this.renderer = new THREE.WebGLRenderer({
canvas: this.canvas,
antialias: true
});
this.renderer.setPixelRatio(devicePixelRatio);
this.renderer.setSize(this.canvas.clientWidth, this.canvas.clientHeight);
this.renderer.shadowMap.enabled = true;
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
this.renderer.setClearColor(0xffffff, 1);
this.renderer.autoClear = true;
let component: MapComponent = this;
(function render() {
requestAnimationFrame(render);
component.render();
}());
}
public render() {
this.renderer.render(this.scene, this.camera);
}
public addControls() {
this.controls = new THREE.OrbitControls(this.camera);
this.controls.rotateSpeed = 1.0;
this.controls.zoomSpeed = 1.2;
this.controls.addEventListener('change', this.render);
}
/* EVENTS */
public onMouseDown(event: MouseEvent) {
console.log("onMouseDown");
event.preventDefault();
// Example of mesh selection/pick:
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
mouse.x = (event.clientX / this.renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.clientY / this.renderer.domElement.clientHeight) * 2 + 1;
raycaster.setFromCamera(mouse, this.camera);
var obj: THREE.Object3D[] = [];
this.findAllObjects(obj, this.scene);
var intersects = raycaster.intersectObjects(obj);
console.log("Scene has " + obj.length + " objects");
console.log(intersects.length + " intersected objects found")
intersects.forEach((i) => {
console.log(i.object); // do what you want to do with object
});
}
private findAllObjects(pred: THREE.Object3D[], parent: THREE.Object3D) {
// NOTE: Better to keep separate array of selected objects
if (parent.children.length > 0) {
parent.children.forEach((i) => {
pred.push(i);
this.findAllObjects(pred, i);
});
}
}
public onMouseUp(event: MouseEvent) {
console.log("onMouseUp");
}
#HostListener('window:resize', ['$event'])
public onResize(event: Event) {
this.canvas.style.width = "100%";
this.canvas.style.height = "100%";
console.log("onResize: " + this.canvas.clientWidth + ", " + this.canvas.clientHeight);
this.camera.aspect = this.getAspectRatio();
this.camera.updateProjectionMatrix();
this.renderer.setSize(this.canvas.clientWidth, this.canvas.clientHeight);
this.render();
}
#HostListener('document:keypress', ['$event'])
public onKeyPress(event: KeyboardEvent) {
console.log("onKeyPress: " + event.key);
}
/* LIFECYCLE */
ngAfterViewInit() {
this.createScene();
this.createCamera();
this.createLight();
this.startRendering();
this.addControls();
}
And map.html is
<canvas #canvas (mousedown)="onMouseDown($event)" (mouseup)="onMouseUp($event)"></canvas>
Use collision detection from three js utilities
Also use reference from this stack thread
https://stackoverflow.com/a/11480717/16768028

CKEditor resizing tabs in dialogs

So I removed a bunch of buttons in the table info dialogs. There are only 5 buttons left, so it feels pretty empty with the default size.
Here are the codes:
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if(dialogName == 'table' || dialogName == 'tableProperties'){
var advTab = dialogDefinition.getContents('advanced');
var infoTab = dialogDefinition.getContents('info');
var advClass = advTab.get('advCSSClasses');
var cmbAlignBut = infoTab.get('cmbAlign');
infoTab.remove('txtSummary');
infoTab.remove('txtCaption');
infoTab.remove('selBorder');
infoTab.remove('txtCellSpace');
infoTab.remove('txtCellPad');
infoTab.remove('selHeaders');
infoTab.remove('cmbAlign');
infoTab.remove('txtBorder');
advClass.type = "select";
advClass.requiredContent = "table(cke-xyz)";
advClass.label = "Table Type";
advClass.default = "normal-table";
advClass.items = [
["Normal", "normal-table"],
["Comparison", "comparison-table"],
["Links", "link-table"]
];
infoTab.add(advClass);
dialogDefinition.removeContents('advanced');
console.log(advClass);
console.log(cmbAlignBut);
}
});
And here's how it looks like:
How do I resize at least the height?
Please see: https://github.com/ckeditor/ckeditor-dev/blob/master/plugins/table/dialogs/table.js#L60
Dialogs usually have minHeight assigned. If you wish to change it, please use :
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if(dialogName == 'table' || dialogName == 'tableProperties'){
ev.data.definition.minHeight = 120; // you can also use ev.data.definition.minHeight = 0;
...

When I convert the collada from meshbasic to meshphong, parts of the collada disappear. Why is that?

When I convert the collada from meshbasic to meshphong, parts of the collada disappear. Why is that?
var setMaterial = function( node ) {
node.material = new THREE.MeshBasicMaterial({color: 0xff0000} );
console.log(node);
if (node.children) {
for (var i=0, thelength=node.children.length; i < thelength ; i++ ) {
setMaterial(node.children[i]);
}
}
}
setMaterial(dae);
This works, but then this makes half of it disappear...
var setMaterial = function( node ) {
node.material = new THREE.MeshBasicPhong({color: 0xff0000} );
console.log(node);
if (node.children) {
for (var i=0, thelength=node.children.length; i < thelength ; i++ ) {
setMaterial(node.children[i]);
}
}
}
setMaterial(dae);
i think there no material in the name THREE.MeshBasicPhong.....
change it as MeshPhongMaterial and have a try..
node.material = new THREE.MeshPhongMaterial({color: 0xff0000} );

Resources