from pointwise import GlyphClient
from pointwise.glyphapi import *
import os


# the foll lines are the python equivalent of this TCL line:
#	package require PWI_Glyph 3.18.3

glf = GlyphClient()
	# you could also have used GlyphClient(portnumber)
	# 	see https://blog.pointwise.com/2018/11/26/glyph-api-for-python/ for more

	# this next line requires a connection to a Glyph Server
	# all this means is that within Pointwise, your Script menu should be set to "Active"
	# see https://www.youtube.com/watch?v=ZjWf1FXB_NM 
pw = glf.get_glyphapi()

	# set the path to the PCD
	# you can use Python's OS package to finetune the folder-names, etc.
	# for eg:
	#   scriptDir = os.path.dirname(os.path.realpath(__file__))
	#   pcdFileName = "myData.pcd"
	#   finalPath = os.path.join(scriptDir, pcdFileName)
	
pcdFileName = "myData.pcd"

	# we now need to replicate these TCL commands:
	#set myAppMode [pw::Application begin SourceImport]
	#  $myAppMode initialize -strict -type Automatic mydata.pcd
	#  $myAppMode setAttribute ImportLayerScheme SingleLayer
	#  $myAppMode setAttribute ImportLayerNumber 50
	#  $myAppMode read
	#  $myAppMode convert
	#$myAppMode end
	#unset myAppMode

with pw.Application.begin("SourceImport") as myImporter:
   #pw.Application.initialize("myData.pcd", type="Automatic")
   myImporter.initialize( "mydata.pcd", type="Automatic")
   myImporter.read()
   myImporter.convert()
   myImporter.end()

glf.close()

