Nous utilisons des cookies pour vous garantir la meilleure expérience sur notre site. Si vous continuez à utiliser ce dernier, nous considèrerons que vous acceptez l'utilisation des cookies. J'ai compris ! ou En savoir plus !.
banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

GEODATA DAYS 2024

#1 Fri 29 June 2012 15:54

Lebon henry
Participant occasionnel
Lieu: Avignon
Date d'inscription: 23 Sep 2007
Messages: 12

Publier un pmf en python

Bonjour, je travaille sous arcmap10 et je voudrais publier des pmf en python. Le but étant de publier des mxd en lot. J'ai trouvé celui-ci :

Code:

# PublishPMF.py
# !!!!Download comtypes installer at http://sourceforge.net/projects/comtypes/

#**** Set params ****

# Set Ver93 to False for 9.4 Beta
Ver93 = True
sProjPath = "c:/apps/Demo"
sMxdPath = sProjPath + "/Hydrants.mxd"
sPmfPath = sProjPath + "/Hydrants.pmf"
bEnableLayout = True

#**** Define helper functions and imports ****

print("Initializing...")

import comtypes
import comtypes.server.localserver
from comtypes.client import GetModule

def NewObj(MyClass, MyInterface):
    from comtypes.client import CreateObject
    try:
        ptr = CreateObject(MyClass, interface=MyInterface)
        return ptr
    except:
        return None

def CType(obj, interface):
    try:
        newobj = obj.QueryInterface(interface)
        return newobj
    except:
        return None

def GetESRILibPath():
    import _winreg
    if Ver93:
        sRegPath = "SOFTWARE\\ESRI\\ArcGIS"
    else:
        sRegPath = "SOFTWARE\\ESRI\\Desktop9.4"
    keyESRI = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, sRegPath)
    return _winreg.QueryValueEx(keyESRI, "InstallDir")[0] + "com\\"

sLibPath = GetESRILibPath();
GetModule(sLibPath + "esriSystem.olb")
GetModule(sLibPath + "esriCarto.olb")
GetModule(sLibPath + "esriPublisher.olb")

from comtypes.gen.esriSystem import *
from comtypes.gen.esriCarto import *
from comtypes.gen.esriPublisher import *

def Init():
    pInit = NewObj(AoInitialize, IAoInitialize)
    eProduct = esriLicenseProductCodeArcView
    eStatus = pInit.IsProductCodeAvailable(eProduct)
    if eStatus != esriLicenseAvailable:
        return False
    eStatus = pInit.Initialize(eProduct)
    if eStatus != esriLicenseCheckedOut:
        return False
    # Check out Publisher
    eExtension = esriLicenseExtensionCodePublisher
    eStatus = pInit.IsExtensionCodeAvailable(eProduct, eExtension)
    if eStatus != esriLicenseAvailable:
        return False
    eStatus = pInit.CheckOutExtension(eExtension)
    if eStatus != esriLicenseCheckedOut:
        return False
    return True

def PublishPMF(pMapDoc, sPath):
    # Configure publisher
    pPub = NewObj(PublisherEngine, IPMFPublish)
    pPropSet = pPub.GetDefaultPublisherSettings()
    pPropSet.SetProperty("DisplayFunctionalityMessage", False)
    pPropSet.SetProperty("OpenOnlyInArcReader", False)
    pPropSet.SetProperty("InternalObjectAccess", True)
    if bEnableLayout:
        pPropSet.SetProperty("DefaultViewType", esriAPEViewTypeAll)
    else:
        pPropSet.SetProperty("DefaultViewType", esriAPEViewTypeDataOnly)
    # Create PMF
    pLayout = pMapDoc.PageLayout
    pMap = pMapDoc.Map(0) # Assume 1 map frame
    pActiveView = CType(pMap, IActiveView)
    bSuccess = True
    try:
        pPub.Publish(pLayout, pActiveView, pPropSet, False, sPath)
    except:
        bSuccess = False
    return bSuccess

#**** Do it ****

def DoIt():
    print "Checking out license..."
    if not Init():
        print "Error:  could not get license."
        return
    # Open mxd
    print "Opening mxd..."
    pMapDoc = NewObj(MapDocument, IMapDocument)
    try:
        pMapDoc.Open(sMxdPath)
    except:
        print "Error opening mxd."
        return
    # Publish PMF
    print "Publishing PMF..."
    bResult = PublishPMF(pMapDoc, sPmfPath)
    pMapDoc.Close()
    if not bResult:
        print "Error publishing pmf."
        return
    print "Done."

DoIt()

Que j'ai modifié comme cela:

Code:

Ver10 = True

sMxdPath = "C:\\MaCarte.mxd"
sPmfPath = "C:\\MaCarte.pmf"
bEnableLayout = True

#**** Define helper functions and imports ****

print("Initializing...")

import comtypes
import comtypes.server.localserver
from comtypes.client import GetModule

def NewObj(MyClass, MyInterface):
    from comtypes.client import CreateObject
    try:
        ptr = CreateObject(MyClass, interface=MyInterface)
        return ptr
    except:
        return None

def CType(obj, interface):
    try:
        newobj = obj.QueryInterface(interface)
        return newobj
    except:
        return None

GetModule("C:\Program Files\ArcGIS\Desktop10.0\com\esriSystem.olb")
GetModule("C:\Program Files\ArcGIS\Desktop10.0\com\esriCarto.olb")
GetModule("C:\Program Files\ArcGIS\Desktop10.0\com\esriPublisher.olb")

from comtypes.gen.esriSystem import *
from comtypes.gen.esriCarto import *
from comtypes.gen.esriPublisher import *

def Init():
    pInit = NewObj(AoInitialize, IAoInitialize)
    eProduct = esriLicenseProductCodeArcView
    eStatus = pInit.IsProductCodeAvailable(eProduct)
    if eStatus != esriLicenseAvailable:
        return False
    eStatus = pInit.Initialize(eProduct)
    if eStatus != esriLicenseCheckedOut:
        return False
    # Check out Publisher
    eExtension = esriLicenseExtensionCodePublisher
    eStatus = pInit.IsExtensionCodeAvailable(eProduct, eExtension)
    if eStatus != esriLicenseAvailable:
        return False
    eStatus = pInit.CheckOutExtension(eExtension)
    if eStatus != esriLicenseCheckedOut:
        return False
    return True

def PublishPMF(pMapDoc, sPath):
    # Configure publisher
    pPub = NewObj(PublisherEngine, IPMFPublish)
    pPropSet = pPub.GetDefaultPublisherSettings()
    pPropSet.SetProperty("DisplayFunctionalityMessage", False)
    pPropSet.SetProperty("OpenOnlyInArcReader", False)
    pPropSet.SetProperty("InternalObjectAccess", True) 
    if bEnableLayout:
        pPropSet.SetProperty("DefaultViewType", esriAPEViewTypeAll)
    else:
        pPropSet.SetProperty("DefaultViewType", esriAPEViewTypeDataOnly)
    # Create PMF
    pLayout = pMapDoc.PageLayout
    pMap = pMapDoc.Map(0) # Assume 1 map frame
    pActiveView = CType(pMap, IActiveView)
    bSuccess = True
    try:
        pPub.Publish(pLayout, pActiveView, pPropSet, False, sPath)
    except Exception as e:
        print e
        bSuccess = False
    return bSuccess

#**** Do it ****

def DoIt():
    print "Checking out license..."
    if not Init():
        print "Error:  could not get license."
        return
    # Open mxd
    print "Opening mxd..."
    pMapDoc = NewObj(MapDocument, IMapDocument)
    try:
        pMapDoc.Open(sMxdPath)
    except:
        print "Error opening mxd."
        return
    # Publish PMF
    print "Publishing PMF..."
    bResult = PublishPMF(pMapDoc, sPmfPath)
    pMapDoc.Close()
    if not bResult:
        print "Error publishing pmf."
        return
    print "Done."

DoIt()

Mais j'ai ce message d'erreur : (-2147467259, 'Erreur non sp\xe9cifi\xe9e', (None, None, None, 0, None)) 

Visiblement un problème avec cette ligne du code :

Code:

pPub.Publish(pLayout, pActiveView, pPropSet, False, sPath

Quelqu'un a-t-il un script qui marche ou peut-il m'aider à faire marcher le mien ?

Merci d'avance. Bonne journée.

Hors ligne

 

Pied de page des forums

Powered by FluxBB