Import file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

trailboss
Posts: 112
Joined: Sat Dec 13, 2008 4:55 pm

Import file

Post by trailboss » Sat Dec 29, 2012 11:49 pm

Well, I'm not a beginner but I'm not ashamed to say that this is a beginner question.
I want to view a jpeg file in a Runtime Rev application that I've made. I don't know how to do this simple thing. I try "open file NovJournal.jpg" and nothing happens.

I have a bird database and I'm entering in 37 years of my parents' bird notes from our house in Mexico. The bird entry is easy, but they've written journals out longhand, and I'm tired of entering it all by typing so I thought I'd scan each page and make it available. If I scan a page a day, I'll be done in a few years.

Any ideas on how I might incorporate scanned writing into a database for viewing would be appreciated, but as I said I don't even know how to get the file to open using RunRev.

Thanks
Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 6:07 pm

Hi Tom,

Pictures are displayed in an image object. Your script needs to create one first and then put the picture data into the image control.

Code: Select all

create img "New Image"
put the long id of it into myImageID
set the text of myImageID to url ("C:/path/to/NovJournal.jpg")
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

trailboss
Posts: 112
Joined: Sat Dec 13, 2008 4:55 pm

Re: Import file

Post by trailboss » Sun Dec 30, 2012 6:16 pm

Thanks, Mark
I've tried:

on mouseUp
create img "New Image"
put the long id of it into myImageID
set the text of myImageID to url ("computer/macintosh hard drive/users/tomcole/retirement folder/estero morua bird database/December5_1975.jpg")
end mouseUp

Nothing happens, however.

Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 6:21 pm

Hi Tom,

Doesn't LiveCode create an image object?

You can view the correct file path in the message box with the syntax

Code: Select all

answer file ""
put it
Select your file in the file dialog and check the file path in the message box.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Import file

Post by FourthWorld » Sun Dec 30, 2012 6:38 pm

The "text" property of an object is its contents. In fields it's the textual data displayed, and in images is the imageData.

To assign an image file to an image object use that object's filename property.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 6:46 pm

Hi,

If you use the filename property of an image object, you're not actually importing that file. OP is asking how to import a file, not how to display a picture on disk. Using the filename property could be an alternative to importing a file, but that solution doesn't answer the OP's question.

If you set the imagedata to the contents of a picture file, you'll get garbage. You have to use the text property, not the imagedata.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

trailboss
Posts: 112
Joined: Sat Dec 13, 2008 4:55 pm

Re: Import file

Post by trailboss » Sun Dec 30, 2012 6:55 pm

I've checked the CARD INSPECTOR and the scripting does create an image but it is kind of invisible. I can select it and that's all. I guess I don't know what I'm doing as usual. I can import my images as controls and put them on pages. And view them that way. Is there an advantage to the way you are suggesting?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 6:59 pm

Hi,

Whom are you asking?

It seems to me that you wanted to do this by script and that you wanted to actually import the file. The script I posted does this.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

trailboss
Posts: 112
Joined: Sat Dec 13, 2008 4:55 pm

Re: Import file

Post by trailboss » Sun Dec 30, 2012 7:07 pm

I was asking Mark. Thanks for your help. I'll keep diddling with this. I can import the files as controls though.
Many thanks,
Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 7:15 pm

Hi Tom,

If it is sufficient for you to import the picture files as control through the File menu, then there is no reason not to use it. I guess that solves it.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Import file

Post by FourthWorld » Sun Dec 30, 2012 7:20 pm

Mark wrote:If you use the filename property of an image object, you're not actually importing that file. OP is asking how to import a file, not how to display a picture on disk. Using the filename property could be an alternative to importing a file, but that solution doesn't answer the OP's question.
Maybe. The OP wrote:
"I want to view a jpeg file in a Runtime Rev application that I've made."
He also mentioned that he has a good may of these images to view. As journal pages I'd guess they're at least 500x700px, possibly larger if scanned at a good resolution. Importing all them into a stack may be overkill, requiring a lot of memory.

Unless there's some specific reason why it would be essential to import them, I'd just leave them on disk and set the filename of an image object.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Sun Dec 30, 2012 7:47 pm

Hi,

I think you're repeating yourself.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

trailboss
Posts: 112
Joined: Sat Dec 13, 2008 4:55 pm

Re: Import file

Post by trailboss » Sun Dec 30, 2012 11:04 pm

Yes, there are a zillion scanned images or there will be. They're big, so I guess it would be best to just view the image. I put a couple in, and they're so big that it takes a second to go from one card to the next. There's an icon on the tools palette called image area. If I make one of those and stick it on a single card it would be nice to make it display the jpg image. Each image that I will store on my hard drive will have as its name a date. It would be good to enter a date and have the image object display the scanned journal page. I just can't get an image object to display. I guess it must be my path or something. computer/macintosh hard drive/users/tomcole/retirement folder/estero morua bird database/december5_1975.jpg

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Import file

Post by Simon » Mon Dec 31, 2012 12:03 am

Hi Tom,
There seems to be too much going on here as what you are asking for is too simple.(I think) As I understand it you just want to show an image, maybe be able to change that image to use just a single card.
On a card use the image tool to drag a square into it, in the inspector call it myImage
In a button script put this code;

Code: Select all

on mouseUp
ask file "Please select an image." -- this is just to get you started, select one of your image files
put it into tFilePath
breakpoint -- Take a look at the tFilePath now.  Remove this breakpoint when you are ready
set the filename of img "myImage" to tFilePath
end mouseUp
Will help more once you've seen how this works.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5138
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Import file

Post by Mark » Mon Dec 31, 2012 11:19 am

Hi Simon,

I'm pretty sure that you mean "answer file" instead of "ask file" because "ask file" won't let you select a file but rather enter a file name in a particular folder to generate a file path where a new file can be written.

I think your script should be

Code: Select all

on mouseUp
  answer file "Please select an image."
  if it is not empty then
    put it into tFilePath
    put tFilePath // display path in message box
    set the filename of img "myImage" to tFilePath
  end if
end mouseUp
Tom, your file path is indeed wrong, as I already indicated in my previous posts. You must have a look at the file path returned by the answer file command, which I also already demonstrated in an earlier post.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”