Export active doc

I know this is simple but I can’t get it to work
What is the code to export as pdf in the same location as the active document.

I’m getting an error:
error “Adobe InDesign CS4 got an error: Can’t get file path of active document of active document.” number -1728 from file path of active document of active document

property myPDFpreset : missing value
tell application "Adobe InDesign CS4"
	activate
	tell active document
		
		set source_folder to file path of active document
		set theName to name of active document -- nombre del file
		set text item delimiters of AppleScript to {"_"}
		set theFilenameWithoutINDD to text item 1 of theName
		set baseName to text item 1 of theFilenameWithoutINDD
		--set part2 to text item 3 of theFilenameWithoutINDD Parte 2 seria lo q vine despues del _
		set text item delimiters of AppleScript to ""
		
		
		--Create folder for PDFs
		tell application "Finder"
			if (exists folder "XX" of folder source_folder) is false then
				make folder at source_folder with properties {name:"XXc"}
			end if
		end tell
		
		
		-->>loop thru pages to create single pages
		repeat with x from 1 to count pages of active document
			set thePageName to name of page x of active document
			set page range of PDF export preferences to thePageName
			-->>section page number must have 3 digits
			set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
			set theFilePath to source_folder & baseName & "_" & "TEST" & "_" & threeDigitPageName & ".pdf" as string
			
			-->>Export PDF
			export active document format PDF type to theFilePath using myPDFpreset without showing options
		end repeat
	end tell
end tell

Notice how you’re using active document twice?

Thank you for your reply Stanley. I’m using active document twice because don’t know what is the syntax code. Do I need address the page or the document? Can you shed some additional light if you can. I know some AS basics, copy & paste code to make things work

If I understand well the posted code, it would be useful to try :

property myPDFpreset : missing value
tell application "Adobe InDesign CS4"
	activate
	# tell active document # DISABLED !
		
		set source_folder to file path of active document
		set theName to name of active document -- nombre del file
		set text item delimiters of AppleScript to {"_"}
		set theFilenameWithoutINDD to text item 1 of theName
		set baseName to text item 1 of theFilenameWithoutINDD
		--set part2 to text item 3 of theFilenameWithoutINDD Parte 2 seria lo q vine despues del _
		set text item delimiters of AppleScript to ""
		
		
		--Create folder for PDFs
		tell application "Finder"
			if (exists folder "XX" of folder source_folder) is false then
				make folder at source_folder with properties {name:"XXc"}
			end if
		end tell
		
		
		-->>loop thru pages to create single pages
		repeat with x from 1 to count pages of active document
			set thePageName to name of page x of active document
			set page range of PDF export preferences to thePageName
			-->>section page number must have 3 digits
			set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
			set theFilePath to source_folder & baseName & "_" & "TEST" & "_" & threeDigitPageName & ".pdf" as string
			
			-->>Export PDF
			export active document format PDF type to theFilePath using myPDFpreset without showing options
		end repeat
	# end tell # DISABLED !
end tell

Yvan KOENIG (VALLAURIS, France) mardi 25 novembre 2014 17:35:34

The idea of using a tell block addressed to the document is to avoid having to repeatedly refer to the document in the enclosed statements. You include the reference to the document using one or the other – not both. Have another look at the wording of your error message, and it explains the problem.