Autolisp DCL - Alignment and Sizing Tiles - lisp

I'm trying to adjust the sizes and locations of the tiles in this DCL dialog box. Basically, I want to make the edit-boxes in the Client box, Job box, and Miscellaneous box to be the same width. However, they each start at different widths due to the different sizes of the text tile's labels. Just setting the width to a fixed value for both edit-box and text tiles doesn't seem to be fixing the issue for me. How do I need to change this code to make the tiles within this dialog box uniform?
As a bonus, I want to also adjust the tiles in the Revision box. I'm assuming this will be using the same solution. I want to have the widths of the edit-boxes of different widths with the labels centered above them.
I have found that DCL files are a slow and painful process for me. Any help with building this dialog box would be helpful. Thank you for your time.
AutoLisp Code:
(defun C:Test01 (/ sPathAndName sDCLModuleName dclFile bContinue)
;; Initializing
(setq sPathAndName "[File's location and name]")
(setq sDCLModuleName "TitleRevUpdate")
(setq bContinue T)
;; File Exists
(if (not (findfile sPathAndName))(progn
(princ "\nError: The DCL file was not found.\n")
(setq bContinue nil)
));if<-progn
;; DCL File
(if bContinue (progn
(setq dclFile (load_dialog sPathAndName))
(if (>= 0 dclFile)(progn
(princ "\nError: DCL file cannot be loaded.\n")
(setq bContinue nil)
));if<-progn
));if<-progn
;; Creating a new module
(if bContinue
(setq bContinue (new_dialog sDCLModuleName dclFile "" '(-1 -1)))
);if
;; Build and run DCL module
(if bContinue (progn
;; User Form
(princ "\nstart_dialog : ")(princ (start_dialog))(terpri)
(unload_dialog dclFile)
));if<-progn
);C:Test01
DCL Code:
TitleRevUpdate : dialog {
key = "Title" ;
label = "Update Title Block and Revision" ;
// Title
: boxed_column {
key = "Column_TitleBoxes" ;
label = "Title" ;
// Client
: boxed_column {
key = "Client_Box" ;
label = "Client" ;
: row { // Row 01 - Name
key = "Row_Client_Name" ;
width = 15 ;
: text {
key = "txt_Client_Name" ;
alignment = right ;
label = "Client's Name" ;
width = 10 ;
}// text
: edit_box {
key = "edbx_Client_Name" ;
alignment = left ;
width = 10 ;
}// edit_box
} //row
: row { // Row 02 - Location
key = "Row_Client_Loc" ;
: text {
key = "txt_Client_Loc" ;
alignment = right ;
label = "Client's Location" ;
width = 10 ;
}// text
: edit_box {
key = "edbx_Client_Loc" ;
alignment = left ;
width = 10 ;
}// edit_box
} //row
} //boxed_column
: spacer {
}// spacer
// Job
: boxed_column {
key = "Job_Box" ;
label = "Job" ;
: row { // Row 03 - Name
key = "Row_Job_Name" ;
: text {
key = "txt_Job_Name" ;
label = "Job's Name" ;
}// text
: edit_box {
key = "edbx_Job_Name" ;
}// edit_box
} //row
: row { // Row 04 - Number
key = "Row_Job_Number" ;
: text {
key = "txt_Job_Number" ;
label = "Job's Number" ;
}// text
: edit_box {
key = "edbx_Job_Number" ;
}// edit_box
} //row
} //boxed_column
: spacer {
}// spacer
// Miscellaneous
: boxed_column {
key = "Miscellaneous_Box" ;
label = "Miscellaneous" ;
: row { // Row 05 - Creator's Initials
key = "Row_Creator_Name" ;
: text {
key = "txt_Creator_Name" ;
label = "Creator's Name" ;
}// text
: edit_box {
key = "edbx_Creator_Name" ;
}// edit_box
} //row
: row { // Row 06 - Date of Creation
key = "Row_Date" ;
: text {
key = "txt_TitleDate" ;
label = "Date" ;
}// text
: edit_box {
key = "edbx_TitleDate" ;
}// edit_box
} //row
: row { // Row 07 - Issued For
key = "Row_Issued_For" ;
: text {
key = "txt_Issued_For" ;
label = "Issued For" ;
}// text
: edit_box {
key = "edbx_Issued_For" ;
}// edit_box
} //row
} //boxed_column
} //boxed_column
: spacer {
}// spacer
// Revision
: boxed_column {
key = "Column_Revision" ;
label = "Revision" ;
: row { // Row 08 - Quick Choices
key = "Row_Buttons" ;
: button {
key = "btn_IFC" ;
label = "Issued for Construction" ;
}// button
: button {
key = "tbn_AB" ;
label = "As Built" ;
}// button
: radio_column {
key = "RadioCol_WriteMethod" ;
: radio_button {
key = "rbtn_Owt" ;
label = "Clear && Overwrite" ;
}// radio_button
: radio_button {
key = "rbtn_Apnd" ;
label = "Append / New Line" ;
}// radio_button
} //radio_column
} //row
: spacer {
}// spacer
: row { // Row 09 - Rev Labels
key = "Row_Labels" ;
: text {
key = "txt_Rev" ;
label = "Rev" ;
}// text
: text {
key = "txt_Initials" ;
label = "Initials" ;
}// text
: text {
key = "txt_Description" ;
label = "Description" ;
}// text
: text {
key = "txt_RevDate" ;
label = "Date" ;
}// text
} //row
: row { // Row 10 - Rev Edit Boxes
key = "Row_Rev" ;
: edit_box {
key = "edbx_Rev" ;
}// edit_box
: edit_box {
key = "edbx_Initials" ;
}// edit_box
: edit_box {
key = "edbx_Date" ;
}// edit_box
: edit_box {
key = "edbx_RevDate" ;
}// edit_box
} //row
} //boxed_column
: spacer {
}// spacer
// Return Commands
: row { // Row 11 - Buttons
key = "Row_Return" ;
: button {
key = "btn_DWGs" ;
action = "(done_dialog 2)" ;
label = "Show Drawings" ;
}// button
: button {
key = "btn_Confirm" ;
action = "(done_dialog 1)" ;
is_enabled = true ;
label = "Confirm" ;
}// button
: button {
key = "btn_Cancel" ;
action = "(done_dialog 0)" ;
is_default = true ;
label = "Cancel" ;
}// button
} //row
: spacer {
}// spacer
} // TitleRevUpdate

The key to edit box alignment in standard DCL is to set the width attribute to be the same for all edit boxes (and large enough to accommodate the text and editing area of the largest edit box in the group), set the fixed_width attribute to true for all edit boxes, and then control the size of the edit box itself using the edit_width attribute.
You don't need separate text tiles when working with edit boxes, instead, you can use the label attribute of the edit_box tile.
For example, the upper section of your DCL could be revised to the following:
TitleRevUpdate : dialog
{
key = "Title" ;
label = "Update Title Block and Revision" ;
spacer;
// Title
: boxed_column
{
label = "Title" ;
// Client
: boxed_column
{
label = "Client" ;
: edit_box
{
label = "Client's Name:";
key = "edbx_Client_Name";
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
: edit_box
{
label = "Client's Location:" ;
key = "edbx_Client_Loc" ;
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
spacer;
}
spacer;
// Job
: boxed_column
{
label = "Job";
: edit_box
{
label = "Job's Name:";
key = "edbx_Job_Name";
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
: edit_box
{
label = "Job's Number:" ;
key = "edbx_Job_Number" ;
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
spacer;
}
spacer;
// Miscellaneous
: boxed_column
{
label = "Miscellaneous" ;
: edit_box
{
key = "edbx_Creator_Name" ;
label = "Creator's Name:" ;
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
: edit_box
{
key = "edbx_TitleDate" ;
label = "Date:" ;
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
: edit_box
{
key = "edbx_Issued_For" ;
label = "Issued For:" ;
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
spacer;
}
spacer;
}
spacer;
// Return Commands
: row
{
key = "Row_Return" ;
fixed_width = true;
alignment = centered;
: button
{
key = "btn_DWGs" ;
action = "(done_dialog 2)" ;
label = "Drawings" ;
fixed_width = true;
width = 16;
}
: button
{
key = "btn_Confirm" ;
action = "(done_dialog 1)" ;
is_enabled = true ;
label = "Confirm" ;
fixed_width = true;
width = 16;
}
: button
{
key = "btn_Cancel" ;
action = "(done_dialog 0)" ;
is_default = true ;
label = "Cancel" ;
fixed_width = true;
width = 16;
}
}
spacer;
}
To yield the following GUI:
And given that all of the tiles are sharing the same attribute values, you can define a named tile to condense the code much further, e.g.:
myeditbox : edit_box
{
alignment = left;
width = 52;
fixed_width = true;
edit_width = 30;
}
mybutton : button
{
fixed_width = true;
width = 16;
}
TitleRevUpdate : dialog
{
key = "Title" ;
label = "Update Title Block and Revision" ;
spacer;
: boxed_column
{
label = "Title" ;
: boxed_column
{
label = "Client" ;
: myeditbox { label = "Client's Name:"; key = "edbx_Client_Name"; }
: myeditbox { label = "Client's Location:"; key = "edbx_Client_Loc" ; }
spacer;
}
spacer;
: boxed_column
{
label = "Job";
: myeditbox { label = "Job's Name:"; key = "edbx_Job_Name"; }
: myeditbox { label = "Job's Number:"; key = "edbx_Job_Number"; }
spacer;
}
spacer;
: boxed_column
{
label = "Miscellaneous" ;
: myeditbox { label = "Creator's Name:"; key = "edbx_Creator_Name"; }
: myeditbox { label = "Date:"; key = "edbx_TitleDate"; }
: myeditbox { label = "Issued For:"; key = "edbx_Issued_For"; }
spacer;
}
spacer;
}
spacer;
: row
{
key = "Row_Return" ;
fixed_width = true;
alignment = centered;
: mybutton { key = "btn_DWGs"; action = "(done_dialog 2)"; label = "Drawings"; }
: mybutton { key = "btn_Confirm"; action = "(done_dialog 1)"; label = "Confirm"; is_enabled = true; }
: mybutton { key = "btn_Cancel" ; action = "(done_dialog 0)"; label = "Cancel"; is_default = true; }
}
spacer;
}

Except
width = 10 ;
You need also
fixed_width = true;
on each edit_box

Related

Lisp Addin Call .dcl File

I'm trying to both learn and implement some lisp code for a cad addin, but I'm running into a calling issue. I'm currently trying to add an error handling for when the user activates this addin, but the file itself is either not located in the correct directory or the file is not saved to a location. I came across a method that will allow me to ask the user a question with a message box, but the lisp file isn't pulling the dcl file. How should this error be resolved?
Scope: The big picture is for the user to either click a button on the ribbon or by typing a command, and all of the files in the same folder as the open, active drawing will receive a revision update.
Application: DraftSight is where the lisp file is being added.
Original Tutorial: Here's the link to the original tutorial where I found the code to build the message box.
Error Message from DraftSight
Code I'm building:
;; Global Constants
(defconstant msgboxPath "C:\\Users\\GarrettB\\Documents\\Visual Studio Code\\DraftSight LISP")
;;
(defun C:ProjectRev()
;; Pulls the directory from the active file
(setq dirPath (vl-catch-all-apply getvar 'dwgprefix))
;; Checks for an error
(if not (vl-catch-all-error-p dirPath)
(progn ; No error - Ask user if this is the right path
(setq UserRespond (lspYesNoCancel "Is this the correct path?" dirfile "" "PROJECT REVISION"))
(princ (type UserRespond))
(princ UserRespond)
;; if yes then continue
;; else ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
(progn ; Error - File is not saved to a directory
;; ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
);if
;; WORK IN PROGRESS
;; Gather drawings into a list
;; Copy drawings and place into "Past revisions" folder
;; Add revision to drawings
;; Modify drawing's names
;; Save, close, and end
)
;; Source: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-on-all-dwg-directory/td-p/6214507
;; Browses the current directory for .dwg files
(defun browseForFolder (title options rootFolder / sh folder folderobject result)
(vl-load-com)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")) ; sets the Shell Terminal variable
;; Obtaining starting location
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-hwnd (vlax-get-acad-object)) title options rootFolder)) ; User sets the folder path and file name as an object?
(vlax-release-object sh) ;-------------------------------------------; Releases the shell application object
(setq sh nil) ;------------------------------------------------------; Sets the sh variable to nothing
; If folder is not nil
(if folder
(progn
;; Conversion
(setq folderobject (vlax-get-property folder 'Self)) ; Sets the folder path as an object
(setq result (vlax-get-property FolderObject 'Path)) ; Sets the folder path as a string
;; Release and nullify
(vlax-release-object folder) ;-----; Releases the folder path and file name as an object?
(vlax-release-object FolderObject) ; Releases the folder path as a string
(setq folder nil) ;----------------; Sets the folder variable to nothing
(setq FolderObject nil) ;----------; Sets the FolderObject variable to nothing
;; Returning variable
result
); progn
); if
); defun browserForFolder
;; Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
;; Lisp code from tutorial
(defun lspYesNoCancel (message1 message2 message3 main)
;; Creating dialoge box
(setq dcl_id (load_dialog strcat(msgboxPath "\\" "msgbox.dcl")))
;; Error prevention
(if (not (new_dialog "lspYesNoCancel" dcl_id)) (exit))
;; Dialoge Message
(set_tile "message1" message1)
(set_tile "message2" message2)
(set_tile "message3" message3)
(set_tile "main" main)
;; Command Buttons
(action_tile "no" "(done_dialog) (setq result \"F\")")
(action_tile "yes" "(done_dialog) (setq result T)")
(action_tile "cancel" "(done_dialog) (setq result nil)")
;; Interaction
(start_dialog) ; Show dialog box
(unload_dialog dcl_id) ; Close dialoge box
(princ)
)
Here's the msgbox.dcl file
// Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
////////////////////////////////////////////////
lspOkCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNo : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////
lspOkOnly : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
alignment = centered;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNoCancel : dialog {
key = "main";
: column {
: text {Key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
lspRentryCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "Rentry";
key = "rentry";
width = 12;
fixed_width = true;
mnemonic = "R";
is_default = true;
}
: button {
label = "Cancel";
key = "Cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
I think the problem is in line:
(setq dcl_id (load_dialog strcat(msgboxPath "\\" "msgbox.dcl")))
Where should be rather:
(setq dcl_id (load_dialog ( strcat msgboxPath "\\" "msgbox.dcl")))

OpenXML / Xceed insert Table without empty lines

I have an existing.docx document with some text. All I want is to insert programmatically a table to a specific place. So my idea was to add a Keyword where the table should be inserted. There are no empty lines, before and after the keyword.
After the insertion of the table I add \n, before and after the table, for an empty line but somehow the Xceed library adds three after the table and two before the table.
Here is how I'm doing it:
using (DocX document = DocX.Load(#"C:\Users\rk\Desktop\test.docx"))
{
var IntTableSoftwareLocation = document.FindAll("Table").FirstOrDefault();
document.ReplaceText("Table", "");
var tableSoftware = document.InsertTable(IntTableSoftwareLocation, 3, 5);
tableSoftware.InsertParagraphBeforeSelf("\n");
tableSoftware.InsertParagraphAfterSelf("\n");
tableSoftware.SetBorder(TableBorderType.InsideH, new Border());
tableSoftware.SetBorder(TableBorderType.InsideV, new Border());
tableSoftware.SetBorder(TableBorderType.Left, new Border());
tableSoftware.SetBorder(TableBorderType.Bottom, new Border());
tableSoftware.SetBorder(TableBorderType.Top, new Border());
tableSoftware.SetBorder(TableBorderType.Right, new Border());
//Header
tableSoftware.Rows[0].Cells[0].Paragraphs[0].Append("Col1").Bold().Font("Arial").FontSize(11d);
tableSoftware.Rows[0].Cells[1].Paragraphs[0].Append("Col2").Bold().Font("Arial").FontSize(11d);
tableSoftware.Rows[0].Cells[2].Paragraphs[0].Append("Col3").Bold().Font("Arial").FontSize(11d);
tableSoftware.Rows[0].Cells[3].Paragraphs[0].Append("Col4.").Bold().Font("Arial").FontSize(11d);
tableSoftware.Rows[0].Cells[4].Paragraphs[0].Append("Col5").Bold().Font("Arial").FontSize(11d);
//Content
string TextToInsert = "Some Text";
//Column width
for (int i = 0; i < tableSoftware.RowCount; i++)
{
for (int x = 0; x < tableSoftware.ColumnCount; x++)
{
#region set column width
if (x == 0)
{
tableSoftware.Rows[i].Cells[x].Width = 28.3; // 1cm
}
else if (x == 1)
{
tableSoftware.Rows[i].Cells[x].Width = 318;
}
else if (x == 2)
{
tableSoftware.Rows[i].Cells[x].Width = 50;
}
else if (x == 3)
{
tableSoftware.Rows[i].Cells[x].Width = 28.3;
}
else if (x == 4)
{
tableSoftware.Rows[i].Cells[x].Width = 64;
}
#endregion
}
}
tableSoftware.Rows[2].Cells[1].Paragraphs[0].Append(TextToInsert + "\n").FontSize(11d).Bold().Font("Arial");
tableSoftware.Rows[2].Cells[2].Paragraphs[0].Append("User").Font("Arial").Alignment = Alignment.center;
tableSoftware.Rows[2].Cells[2].VerticalAlignment = VerticalAlignment.Center;
tableSoftware.Rows[2].Cells[3].Paragraphs[0].Append("1").Font("Arial").Alignment = Alignment.center;
tableSoftware.Rows[2].Cells[3].VerticalAlignment = VerticalAlignment.Center;
tableSoftware.Rows[2].Cells[4].Paragraphs[0].Append("2.199,00 €").Font("Arial").Alignment = Alignment.right;
tableSoftware.Rows[2].Cells[4].VerticalAlignment = VerticalAlignment.Center;
document.Save();
}
And thats how my docx Document looks like:
laksjdf
Table
alskdfjs
Ok, this is how it should be done:
//Find the Paragraph by keyword
var paraTable = document.Paragraphs.FirstOrDefault(x => x.Text.Contains("Table"));
// Remove the Keyword
paraTable.RemoveText(0);
//Insert the table into Paragraph
var table = paraTable.InsertTableAfterSelf(3, 5);
No strange empty lines anymore

after effects - selecting render queue items via script

i'm looking for a way to select items in the render queue via script.
i'm creating a listBox that contains all the RQ items ( i need to list them in a simpler way then the RQ window, and i'm keeping the index number of each item), and i want to select from that list items and select them in the RQ.
ideas?
thanks
Dror
try{
function createUserInterface (thisObj,userInterfaceString,scriptName){
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,
undefined,{resizeable: true});
if (pal == null) return pal;
var UI=pal.add(userInterfaceString);
pal.layout.layout(true);
pal.layout.resize();
pal.onResizing = pal.onResize = function () {
this.layout.resize();
}
if ((pal != null) && (pal instanceof Window)) {
pal.show();
}
return UI;
};
{var res ="group {orientation:'column',\
alignment:['fill','fill'],\
alignChildren:['fill','top'],\
folderPathListbox:ListBox{\
alignment:['fill','fill'],\
properties:{\
multiline:true,\
multiselect:true,\
numberOfColumns:6,\
showHeaders:true,\
columnTitles: ['#','OM','Date','Time', 'Comp Name', 'Render Path']}\
},\
buttonGroup:Group{orientation:'row',\
alignment:['fill','bottom']\
alignChildren:['fill','bottom'],\
buttonPanel: Panel{\
text:'Actions',\
orientation: 'row',\
alignment:['fill','bottom']\
refButton: Button{text:'Refresh'}\
dupButton: Button{text:'Duplicate'}\
selButton: Button{text:'Select in RQ'}\
expButton: Button{text:'Export'}\
}\
searchPanel: Panel{\
text:'Search',\
orientation: 'row',\
searchBox: EditText{text:'search by fileName'},\
searchButton: Button{text:'Search'}, \
}\
}\
}";
}
function listRQ (rqList){
try{
var folderPathListbox = rqList;
var proj = app.project;
var totalRenderQ = proj.renderQueue.numItems;
for(var i= 1; i<=totalRenderQ; i++){
var totalOM= proj.renderQueue.item(i).numOutputModules;
for (var om= 1; om<=totalOM; om++){
var dateList, timeList, curItem;
if (proj.renderQueue.item(i).startTime != null){
var min = proj.renderQueue.item(i).startTime.getMinutes() <10 ? "0"+ proj.renderQueue.item(i).startTime.getMinutes() : proj.renderQueue.item(i).startTime.getMinutes();
var year = proj.renderQueue.item(i).startTime.getFullYear().toString().substr (-2,2);
timeList = (proj.renderQueue.item(i).startTime.getHours()-1)+":" + min;
dateList =proj.renderQueue.item(i).startTime.getDate()+"/"+(proj.renderQueue.item(i).startTime.getMonth()+1)+"/"+year ;
}else{
dateList = "not ";
timeList = "rendered";
}
curItem = folderPathListbox.add ('item', i ); // Column 1
curItem.subItems[0].text = om; // Column 2
curItem.subItems[1].text = dateList.toString(); // Column 3
curItem.subItems[2].text = timeList.toString(); // Column 4
curItem.subItems[3].text = proj.renderQueue.item(i).comp.name; // Column 5
curItem.subItems[4].text = proj.renderQueue.item(i).outputModule(om).file.toString().replace(new RegExp(",","g"), "\r").replace(new RegExp("%20","g"), " ").replace(new RegExp("%5B","g"), "[").replace(new RegExp("%5D","g"), "]"); // Column 6
}
}
}catch(err){alert(err)}
return folderPathListbox;
}
var UI = createUserInterface(this,res,"Better RQ");
var myList = UI.folderPathListbox;
var lsRq = listRQ(myList);
//~ alert(lsRq.toString());
{ // buttons action
UI.buttonGroup.buttonPanel.refButton.onClick = function () {
lsRq.removeAll();
listRQ(myList);
writeLn("all done");
}
UI.buttonGroup.buttonPanel.dupButton.onClick = function () {
var lstSlct = new Array ;
lstSlct = myList.selection;
if ( lstSlct != null){
var totalDup = lstSlct.length;
for (var i= 0; i<totalDup; i++){
var lsId = lstSlct[i].toString();
var dup = parseInt(lsId);
app.project.renderQueue.item(dup).duplicate();
writeLn("duplicated #"+dup);
}
}else{
alert ("select Something");
}
}
UI.buttonGroup.buttonPanel.selButton.onClick = function () {
app.project.renderQueue.showWindow(true) ; //shows the RQ
alert ("selButton");
}
UI.buttonGroup.buttonPanel.expButton.onClick = function () {
// var compName = myList.
alert ("expButton");
}
}
}
catch(err){
alert ("Error at line # " + err.line.toString() + "\r" + err.toString());
}

Getting Facebook profile Album without Iterating through every profile albums

function getAlbumCovers() {
//first check to see if profile pics already exist in user model
//create a collection
var usersCollection = Alloy.Collections.user;
facebookModule.requestWithGraphPath('me/albums', {
fields : 'id,name,cover_photo,count,created_time'
}, 'GET', function(graphResp) {
//show view indicator before data is fetched
//$.view_indicator.visible = true;
setViewIndicator(100, 100, levelColour, 10, true, '30%');
$.ind.top = '30';
if (graphResp.success) {
if (graphResp.result) {
var rows = [];
var data = JSON.parse(graphResp.result).data;
var i = 0;
var blob;
for (x in data) {
if (data[x].name == "Profile Pictures") {
Ti.API.debug(JSON.stringify(data[x]));
var numberPhotos = null;
var albumTitle = null;
//apply transformations
if (data[x].count == null) {
numberPhotos = 0;
} else {
numberPhotos = data[x].count;
if (numberPhotos > 10) {
numberPhotos = 10;
} else {
numberPhotos = numberPhotos;
}
}
albumTitle = data[x].name + ' (' + numberPhotos + ')';
console.log("https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + Alloy.Globals.facebookModule.accessToken + "&type=album");
//start
// Read the image as a blob
var url = "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + Alloy.Globals.facebookModule.accessToken + "&type=album";
var imgView = Ti.UI.createImageView({
image : url,
width : 'auto',
height : 'auto'
});
var imgBlob = imgView.toBlob();
var height = imgBlob.height;
var width = imgBlob.width;
if (height > width) {
var pos = (height - width) / 2;
var dict = {
height : width,
width : width,
x : 0,
y : pos
};
var newImg = imgBlob.imageAsCropped(dict);
//alert(newImg.height);
} else if (height < width) {
var pos = (width - height) / 2;
var dict = {
height : height,
width : height,
x : pos,
y : 0
};
var newImg = imgBlob.imageAsCropped(dict);
//alert(newImg.width);
} else {
//alert(imgBlob.width + '-' + imgBlob.height);
var pos = (width - height) / 2;
var dict = {
height : height,
width : height,
x : pos,
y : 0
};
var newImg = imgBlob.imageAsCropped(dict);
}
imgBlob = null;
//end
var row = Titanium.UI.createTableViewRow({
titleAlb : data[x].name,
selectedBackgroundColor : 'transparent',
selectionStyle : 'Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE on createTableViewRow',
width : '100%',
height : '60'
});
var image = Titanium.UI.createImageView({
//image : "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + Alloy.Globals.facebookModule.accessToken + "&type=album",
image : newImg,
top : 10,
borderColor : levelColour,
left : 30,
width : '40',
height : '40'
});
if (Alloy.Globals.Platform == 'old') {
var title = Titanium.UI.createLabel({
text : albumTitle,
font : {
visible : true,
color : '#888888',
fontFamily : 'Avenir-Roman',
size : 12,
},
width : 200,
top : 15,
color : levelColour,
right : '30dp',
height : 'auto'
});
} else if (Alloy.Globals.Platform == '6') {
var title = Titanium.UI.createLabel({
text : albumTitle,
font : {
visible : true,
color : '#888888',
fontFamily : 'Avenir-Roman',
size : 12,
},
width : 200,
top : 15,
color : levelColour,
right : '85dp',
height : 'auto'
});
} else if (Alloy.Globals.Platform == '6+') {
var title = Titanium.UI.createLabel({
text : albumTitle,
font : {
visible : true,
color : '#888888',
fontFamily : 'Avenir-Roman',
size : 12,
},
width : 200,
top : 15,
color : levelColour,
right : '105dp',
height : 'auto'
});
}
row.add(image);
row.add(title);
rows.push(row);
i++;
console.log(i);
//set table rows
$.tableview.setData(rows);
//end
$.view_indicator.visible = false;
break;
}
}
}
} else {
$.view_indicator.visible = false;
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
}
Here is my code, as you can see I am having calling the Facebook api graph iterating through every album, and then detecting the profile album. The problem with this approach is that if the user has a 1000 albums, the for loop can take forever to find the profile album.
Anyone know of a quicker way to do this?
Cheers
Currently there is no such mechanism available in Graph API.
Also, your proposed method is unreliable at best, since not everybody uses Facebook in the English language, and for those that don't, the album might not be called "Profile Pictures".
The best way to get a user's current profile picture (without the album) is by fetching /user/picture

Calendar view instead of UIDatePicker [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does anyone know of a view controller for iPhone/iPad that shows a monthly calendar?
I Google a lot for showing Month View / Calendar View in my Titanium application but unable to find it out which work on IPhone and Android (Almost all the screens) Both.
After that I tried to implement it by my own and got the good implementation.
To achieve this, Create project which support Android & IPhone.
Open app.js and replace the following code with the existing code and after that Press Command + Shift + F to format the code.
// Taking Screen Width
var screenWidth = 322;
var needToChangeSize = false;
var screenWidthActual = Ti.Platform.displayCaps.platformWidth;
if (Ti.Platform.osname === 'android') {
if (screenWidthActual >= 641) {
screenWidth = screenWidthActual;
needToChangeSize = true;
}
}
// Main Window of the Month View.
var win = Ti.UI.createWindow({
backgroundColor : '#FF000000',
navBarHidden : true
});
// Button at the buttom side
var backButton = Ti.UI.createButton({
bottom : '20dp',
height : '40dp',
width : '200dp'
});
// Previous Button - Tool Bar
var prevMonth = Ti.UI.createButton({
left : '15dp',
width : 'auto',
height : 'auto',
title : '<'
});
// Next Button - Tool Bar
var nextMonth = Ti.UI.createButton({
right : '15dp',
width : 'auto',
height : 'auto',
title : '>'
});
// Month Title - Tool Bar
var monthTitle = Ti.UI.createLabel({
width : '200dp',
height : '24dp',
textAlign : 'center',
color : '#3a4756',
font : {
fontSize : 20,
fontWeight : 'bold'
}
});
// Tool Bar
var toolBar = Ti.UI.createView({
top : '0dp',
width : '322dp',
height : '50dp',
backgroundColor : '#FFFFD800',
layout : 'vertical'
});
// Tool Bar - View which contain Title Prev. & Next Button
var toolBarTitle = Ti.UI.createView({
top : '3dp',
width : '322dp',
height : '24dp'
});
toolBarTitle.add(prevMonth);
toolBarTitle.add(monthTitle);
toolBarTitle.add(nextMonth);
// Tool Bar - Day's
var toolBarDays = Ti.UI.createView({
top : '2dp',
width : '322dp',
height : '22dp',
layout : 'horizontal',
left : '-1dp'
});
toolBarDays.sunday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Sun',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.monday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Mon',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.tuesday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Tue',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.wednesday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Wed',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.thursday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Thu',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.friday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Fri',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.saturday = Ti.UI.createLabel({
left : '0dp',
height : '20dp',
text : 'Sat',
width : '46dp',
textAlign : 'center',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#3a4756'
});
toolBarDays.add(toolBarDays.sunday);
toolBarDays.add(toolBarDays.monday);
toolBarDays.add(toolBarDays.tuesday);
toolBarDays.add(toolBarDays.wednesday);
toolBarDays.add(toolBarDays.thursday);
toolBarDays.add(toolBarDays.friday);
toolBarDays.add(toolBarDays.saturday);
// Adding Tool Bar Title View & Tool Bar Days View
toolBar.add(toolBarTitle);
toolBar.add(toolBarDays);
// Function which create day view template
dayView = function(e) {
var label = Ti.UI.createLabel({
current : e.current,
width : '46dp',
height : '44dp',
backgroundColor : '#FFDCDCDF',
text : e.day,
textAlign : 'center',
color : e.color,
font : {
fontSize : 20,
fontWeight : 'bold'
}
});
return label;
};
monthName = function(e) {
switch(e) {
case 0:
e = 'January';
break;
case 1:
e = 'February';
break;
case 2:
e = 'March';
break;
case 3:
e = 'April';
break;
case 4:
e = 'May';
break;
case 5:
e = 'June';
break;
case 6:
e = 'July';
break;
case 7:
e = 'August';
break;
case 8:
e = 'September';
break;
case 9:
e = 'October';
break;
case 10:
e = 'November';
break;
case 11:
e = 'December';
break;
};
return e;
};
// Calendar Main Function
var calView = function(a, b, c) {
var nameOfMonth = monthName(b);
//create main calendar view
var mainView = Ti.UI.createView({
layout : 'horizontal',
width : '322dp',
height : 'auto',
top : '50dp'
});
//set the time
var daysInMonth = 32 - new Date(a, b, 32).getDate();
var dayOfMonth = new Date(a, b, c).getDate();
var dayOfWeek = new Date(a, b, 1).getDay();
var daysInLastMonth = 32 - new Date(a, b - 1, 32).getDate();
var daysInNextMonth = (new Date(a, b, daysInMonth).getDay()) - 6;
//set initial day number
var dayNumber = daysInLastMonth - dayOfWeek + 1;
//get last month's days
for ( i = 0; i < dayOfWeek; i++) {
mainView.add(new dayView({
day : dayNumber,
color : '#8e959f',
current : 'no',
dayOfMonth : ''
}));
dayNumber++;
};
// reset day number for current month
dayNumber = 1;
//get this month's days
for ( i = 0; i < daysInMonth; i++) {
var newDay = new dayView({
day : dayNumber,
color : '#3a4756',
current : 'yes',
dayOfMonth : dayOfMonth
});
mainView.add(newDay);
if (newDay.text == dayOfMonth) {
newDay.color = 'white';
// newDay.backgroundImage='../libraries/calendar/pngs/monthdaytiletoday_selected.png';
newDay.backgroundColor = '#FFFFF000';
var oldDay = newDay;
}
dayNumber++;
};
dayNumber = 1;
//get remaining month's days
for ( i = 0; i > daysInNextMonth; i--) {
mainView.add(new dayView({
day : dayNumber,
color : '#8e959f',
current : 'no',
dayOfMonth : ''
}));
dayNumber++;
};
// this is the new "clicker" function, although it doesn't have a name anymore, it just is.
mainView.addEventListener('click', function(e) {
if (e.source.current == 'yes') {
// reset last day selected
if (oldDay.text == dayOfMonth) {
oldDay.color = 'white';
// oldDay.backgroundImage='../libraries/calendar/pngs/monthdaytiletoday.png';
oldDay.backgroundColor = '#FFFFF000';
} else {
oldDay.color = '#3a4756';
// oldDay.backgroundImage='../libraries/calendar/pngs/monthdaytile-Decoded.png';
oldDay.backgroundColor = '#FFDCDCDF'
}
oldDay.backgroundPaddingLeft = '0dp';
oldDay.backgroundPaddingBottom = '0dp';
// set window title with day selected, for testing purposes only
backButton.title = nameOfMonth + ' ' + e.source.text + ', ' + a;
// set characteristic of the day selected
if (e.source.text == dayOfMonth) {
// e.source.backgroundImage='../libraries/calendar/pngs/monthdaytiletoday_selected.png';
e.source.backgroundColor = '#FFFF00FF';
} else {
// e.source.backgroundImage='../libraries/calendar/pngs/monthdaytile_selected.png';
e.source.backgroundColor = '#FFFF0000';
}
e.source.backgroundPaddingLeft = '1dp';
e.source.backgroundPaddingBottom = '1dp';
e.source.color = 'white';
//this day becomes old :(
oldDay = e.source;
}
});
return mainView;
};
// what's today's date?
var setDate = new Date();
a = setDate.getFullYear();
b = setDate.getMonth();
c = setDate.getDate();
// add the three calendar views to the window for changing calendars with animation later
var prevCalendarView = null;
if (b == 0) {
prevCalendarView = calView(a - 1, 11, c);
} else {
prevCalendarView = calView(a, b - 1, c);
}
prevCalendarView.left = (screenWidth * -1) + 'dp';
var nextCalendarView = null;
if (b == 0) {
nextCalendarView = calView(a + 1, 0, c);
} else {
nextCalendarView = calView(a, b + 1, c);
}
nextCalendarView.left = screenWidth + 'dp';
var thisCalendarView = calView(a, b, c);
if (needToChangeSize == false) {
thisCalendarView.left = '-1dp';
}
monthTitle.text = monthName(b) + ' ' + a;
backButton.title = monthName(b) + ' ' + c + ', ' + a;
// add everything to the window
win.add(toolBar);
win.add(thisCalendarView);
win.add(nextCalendarView);
win.add(prevCalendarView);
win.add(backButton);
// yeah, open the window, why not?
win.open({
modal : true
});
var slideNext = Titanium.UI.createAnimation({
// left : '-322',
duration : 500
});
slideNext.left = (screenWidth * -1);
var slideReset = Titanium.UI.createAnimation({
// left : '-1',
duration : 500
});
if (needToChangeSize == false) {
slideReset.left = '-1';
} else {
slideReset.left = ((screenWidth - 644) / 2);
}
var slidePrev = Titanium.UI.createAnimation({
// left : '322',
duration : 500
});
slidePrev.left = screenWidth;
// Next Month Click Event
nextMonth.addEventListener('click', function() {
if (b == 11) {
b = 0;
a++;
} else {
b++;
}
thisCalendarView.animate(slideNext);
nextCalendarView.animate(slideReset);
setTimeout(function() {
thisCalendarView.left = (screenWidth * -1) + 'dp';
if (needToChangeSize == false) {
nextCalendarView.left = '-1dp';
} else {
nextCalendarView.left = ((screenWidth - 644) / 2);
}
prevCalendarView = thisCalendarView;
thisCalendarView = nextCalendarView;
if (b == 11) {
nextCalendarView = calView(a + 1, 0, c);
} else {
nextCalendarView = calView(a, b + 1, c);
}
monthTitle.text = monthName(b) + ' ' + a;
nextCalendarView.left = screenWidth + 'dp';
win.add(nextCalendarView);
}, 500);
});
// Previous Month Click Event
prevMonth.addEventListener('click', function() {
if (b == 0) {
b = 11;
a--;
} else {
b--;
}
thisCalendarView.animate(slidePrev);
prevCalendarView.animate(slideReset);
setTimeout(function() {
thisCalendarView.left = screenWidth + 'dp';
if (needToChangeSize == false) {
prevCalendarView.left = '-1dp';
} else {
prevCalendarView.left = ((screenWidth - 644) / 2);
}
nextCalendarView = thisCalendarView;
thisCalendarView = prevCalendarView;
if (b == 0) {
prevCalendarView = calView(a - 1, 11, c);
} else {
prevCalendarView = calView(a, b - 1, c);
}
monthTitle.text = monthName(b) + ' ' + a;
prevCalendarView.left = (screenWidth * -1) + 'dp';
win.add(prevCalendarView);
}, 500);
});
Tested Environment
Titanium Studio - 2.1.2.201208301612
Titanium SDK - 2.1.0.GA
Android - 2.2 Emulator
iOS Version - 5.0
Reference - http://titaniumexplorers.blogspot.in/2012/09/titanium-calendar-month-view.html
There is no in-built view controller for that. You will need to create your own. There are projects in Github for that exact purpose.
Check these out.
Titanium Calendar
Klazuka
Check out the new calendar module which seems to do exactly what you're asking for.