« DTD Node Kind Constants | トップページ | TTMLからFFMETADATA1を生成するちょっと追加 »

イラストレーター用バリアブル印刷用XMLの初期化(途中)

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


#################################
########### DTD
#################################
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setPublicID:"-//W3C//DTD SVG 20001102//EN"
ocidDTD's setSystemID:"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"
ocidDTD's setName:"svg"


#################################
### NSXMLDTDNode ここでは ENTITY
#################################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_graphs"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Graphs/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_vars"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Variables/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_imrep"
ocidDTDNode's setStringValue:"http://ns.adobe.com/ImageReplacement/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_custom"
ocidDTDNode's setStringValue:"http://ns.adobe.com/GenericCustomNamespace/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_flows"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Flows/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_extend"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Extensibility/1.0/"
ocidDTD's addChild:ocidDTDNode


#################################
########### Root element
#################################
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"svg"
#################################
########### variableSets element
#################################
set ocidVariableSets to refMe's NSXMLElement's alloc()'s initWithName:"variableSets"
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"" stringValue:"&ns_vars;"
ocidVariableSets's addNamespace:ocidNameSpaceNode
ocidRootElement's addChild:ocidVariableSets

#################################
########### variableSet element
#################################
set ocidVariableSet to refMe's NSXMLElement's alloc()'s initWithName:"variableSet"
set ocidVariableSetNode to refMe's NSXMLNode's attributeWithName:"varSetName" stringValue:"データセット名"
ocidVariableSet's addAttribute:ocidVariableSetNode
set ocidVariableSetNode to refMe's NSXMLNode's attributeWithName:"locked" stringValue:"none"
ocidVariableSet's addAttribute:ocidVariableSetNode
ocidVariableSets's addChild:ocidVariableSet
#################################
########### variables element
#################################
set ocidVariables to refMe's NSXMLElement's alloc()'s initWithName:"variables"
ocidVariableSet's addChild:ocidVariables
#################################
########### variable element
#################################
set ocidVariable to refMe's NSXMLElement's alloc()'s initWithName:"variable"
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"varName" stringValue:"可変:名前"
ocidVariable's addAttribute:ocidVariableNode
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"trait" stringValue:"textcontent"
ocidVariable's addAttribute:ocidVariableNode
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"category" stringValue:"http://ns.adobe.com/Flows/1.0/"
ocidVariable's addAttribute:ocidVariableNode
ocidVariables's addChild:ocidVariable

#################################
########### sampleDataSets element
#################################
set ocidSampleDataSets to refMe's NSXMLElement's alloc()'s initWithName:"v:sampleDataSets"
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"" stringValue:"http://ns.adobe.com/GenericCustomNamespace/1.0/"
ocidSampleDataSets's addNamespace:ocidNameSpaceNode
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"v" stringValue:"http://ns.adobe.com/Variables/1.0/"
ocidSampleDataSets's addNamespace:ocidNameSpaceNode
ocidVariableSet's addChild:ocidSampleDataSets

#################################
########### sampleDataSet element
#################################
set ocidSampleDataSet to refMe's NSXMLElement's alloc()'s initWithName:"v:sampleDataSet"
set ocidSampleDataSetNode to refMe's NSXMLNode's attributeWithName:"dataSetName" stringValue:"可変:セット1"
ocidSampleDataSet's addAttribute:ocidSampleDataSetNode
ocidSampleDataSets's addChild:ocidSampleDataSet

#################################
########### 可変データセット1
#################################
set ocidSampleDataSetItem to refMe's NSXMLElement's alloc()'s initWithName:"可変:名前"
ocidSampleDataSet's addChild:ocidSampleDataSetItem

#################################
########### 可変データセット1 の項目1
#################################
set ocidSampleDataSetItemP to refMe's NSXMLElement's alloc()'s initWithName:"p"
ocidSampleDataSetItem's addChild:ocidSampleDataSetItemP
ocidSampleDataSetItemP's setStringValue:"名前データ"

#################################
###NSXMLDocument を生成する
#################################
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:ocidRootElement
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
#####DTDを追加
ocidOutPutXML's setDTD:ocidDTD

#################################
###改行コード変換
#################################
####テキスト形式に戻して
set ocidXMLstrings to ocidOutPutXML's XMLString()
####改行コードをCRLF WINDOWSにする
###StringValue内に改行があると置き換えちゃうのでこれはNG
##set ocidCRLFstrings to ocidXMLstrings's stringByReplacingOccurrencesOfString:"\n" withString:"\r\n"
###XMLStringには改行が含まれないためWindows改行にするには最後にWINDOW改行を入れれば良い
ocidCRLFstrings's appendString:"\r\n"
########
(* わざわざ正規表現使わなくても
set ocidCRLFstrings to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidCRLFstrings's setString:ocidXMLstrings
set ocidRange to ocidXMLstrings's rangeOfString:ocidCRLFstrings
ocidCRLFstrings's replaceOccurrencesOfString:"(>)\n" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
ocidCRLFstrings's replaceOccurrencesOfString:"(>)$" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
ocidCRLFstrings's replaceOccurrencesOfString:"\n$" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
*)
####################
####保存
####################
####ファイルパス
set strSaveFilePath to "~/Desktop/AiVariables.xml" as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:strSaveFilePath
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath

####################
#####UTF8でテキストデータにして
set ocidCFLFdata to ocidCRLFstrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###NSDATAとして保存
set listResults to ocidCFLFdata's writeToURL:ocidSaveFilePathURL options:(refMe's NSDataWritingAtomic) |error|:(reference)

|

« DTD Node Kind Constants | トップページ | TTMLからFFMETADATA1を生成するちょっと追加 »

AppleScript Illustrator」カテゴリの記事

AppleScript XML SVG」カテゴリの記事