odbname = data.jobname + '.odb'
mySession = session.openOdb(name = odbname)
myViewport = session.viewports["Viewport: 1"]
#plot stress
myViewport.setValues(displayedObject=mySession)
myViewport.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,))
myViewport.view.fitView()
session.viewports['Viewport: 1'].viewportAnnotationOptions.setValues(
legendFont='-*-verdana-medium-r-normal-*-*-120-*-*-p-*-*-*')
when i run this program am able to see the view iso i need to get the view in front view direction so can anyone tell me how to change to view using python coding
this are my import module
from abaqus import * # from the main library
from caeModules import * # import the modules
from abaqusConstants import * # constants we need
from math import fabs
from abaqus import backwardCompatibility
backwardCompatibility.setValues(reportDeprecated=False)
import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
For abaqus the easiest thing to do watch the replay output generated by abaqus cae. Open the model manually in CAE and change the view to what you would like to see. Abaqus writes a python replay file of all the actions the user takes in the CAE window. Navigate to your working folder and find the file named abaqus.rpy. The last lines in that will be the python commands to replicate your actions in CAE.
Related
I wrote a basic ABAQUS script in Python to extract the values of stresses of a node set. It works fine if I run it through ABAQUS CAE (File -> Run Script) but if I try to utilize the command line it spits out an error. I use the following command:
abaqus cae noGUI=script.py
Basically is supposed to be the same but without a graphical interface
from abaqus import *
from abaqusConstants import *
import os
import numpy as np
import displayGroupOdbToolset as dgo
from odbAccess import *
from driverUtils import *
import csv
#Open results file
odb = session.openOdb(name='C:\Users\...')
session.viewports['Viewport: 1'].setValues(displayedObject=odb)
#Filter Nodes
leaf = dgo.LeafFromNodeSets(nodeSets=('SET-10', ))
session.viewports['Viewport: 1'].odbDisplay.displayGroup.replace(leaf=leaf)
# Create Viewport
session.viewports['Viewport: 1'].makeCurrent()
session.fieldReportOptions.setValues(reportFormat=COMMA_SEPARATED_VALUES)
#Extract Stress Values
session.writeFieldReport(fileName="data1.csv", append=ON,
sortItem='Node Label', odb=odb, step=0, frame=1, outputPosition=NODAL,
variable=(('S', INTEGRATION_POINT, ((COMPONENT, 'S11'),(COMPONENT, 'S22'),
(COMPONENT, 'S33'), (COMPONENT, 'S12'),
(INVARIANT, 'Mises'), )),))
print('Done')
The errors is: ImportError: No module named displayGroupOdbToolset
It seems that it cannot load this module that I utilize for filtering nodes. I also tried to launch this command:
abaqus viewer noGui=script.py
Same results. Am I missing something obvious?
I am trying to run the following code:
from pm4py.algo.discovery.alpha import factorial as alpha_miner
from pm4py.objects.log.importer.xes import factory as xes_importer
event_log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes"))
net, initial_marking, final_marking = alpha_miner.apply(event_log)
gviz = pn_vis_factory.apply(net, initial_marking, final_marking)
pn_vis_factory.view(gviz)
However, when I run the alpha miner, I get an error message that factory cannot be imported.
What could be the reason or does anyone know a soulution for this?
Many thanks for the answer
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
Find all process discoveries and its information at:
https://pm4py.fit.fraunhofer.de/documentation#discovery
Try this:
import os
# Alpha Miner
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
# XES Reader
from pm4py.objects.log.importer.xes import importer as xes_importer
# Visualize
from pm4py.visualization.petri_net import visualizer as pn_visualizer
log = xes_importer.apply(os.path.join("tests","input_data","running-example.xes"))
net, initial_marking, final_marking = alpha_miner.apply(log)
gviz = pn_visualizer.apply(net, initial_marking, final_marking)
pn_visualizer.view(gviz)
I would like to ask for help to modify/edit the mesh of a Part Instance (under Assembly).
I have tried (code below), but it is not possible because of the tuple:
mdb.models[modelName].rootAssembly.instances[instanceName].nodes[i].coordinates[0] = newCoordXYZ[0] # for x
mdb.models[modelName].rootAssembly.instances[instanceName].nodes[i].coordinates[1] = newCoordXYZ[1] # for y
mdb.models[modelName].rootAssembly.instances[instanceName].nodes[i].coordinates[2] = newCoordXYZ[2] # for z
TypeError: 'tuple' object does not support item assignment
Or, if possible, to directly add/assign the mesh (which is already stored in a variable - newCoordXYZ) to the geometry in the Assembly module!?
Any idea/suggestion is more than welcomed!
PS: I know that the modification of the mesh can be easily done in the Part Module (mesh dependent) with the editNode() command.
partName = mdb.models[modelName].parts[partName]
partName.editNode(nodes=partName.nodes,coordinates=newCoordXYZ)
EDIT 01:
comment
I'm not sure, I might make so trivial mistake.
I still obtain the following error: AttributeError: 'PartInstance' object has no attribute 'editNode', which is in agreement with the documentation:
The documentation says:
Abaqus > Scripting Reference > Python commands > Assembly commands > Assembly object:
Access
import assembly
mdb.models[name].rootAssembly
Abaqus > Scripting Reference > Python commands > Assembly commands > PartInstance object:
Access
import assembly
mdb.models[name].rootAssembly.allinstances
mdb.models[name].rootAssembly.instances[name]
and
Abaqus > Scripting Reference > Python commands > Edit mesh commands > Assembly object: editNode(...)
This method changes the coordinates of the given nodes on a part instance.
Abaqus > Scripting Reference > Python commands > Edit mesh commands > Part object
has no editNode(...) cmd
So, by using this cmd: mdb.models[name].rootAssembly.instances[name] I cannot use editNode()...
py code
################################## LIBRARY #############################
from datetime import date
from part import *
from material import *
from section import *
from assembly import *
from step import *
from interaction import *
from load import *
from mesh import *
from optimization import *
from job import *
from sketch import *
from visualization import *
from connectorBehavior import *
import regionToolset
import assembly
import visualization
import os
import datetime
import shutil
from odbAccess import *
import time
import numpy
import numpy as np
import re
import meshEdit
############### Add textFileName with new coord (+ imp )######################
fileNameImp = open("out_newCoordX_Imp.txt","r")
impVect = fileNameImp.readlines()
fileNameImp.close()
####################### Add modelName and instanceName #######################
modelName = 'Model-1'
instanceName = 'Part-1-1'
assemblyInstance = mdb.models[modelName].rootAssembly.instances[instanceName]
newCoordXYZ = numpy.zeros((len(assemblyInstance.nodes),3))
for i in assemblyInstance.nodes:
newCoordXYZ[i.label-1][0] = float(impVect[i.label-1])
newCoordXYZ[i.label-1][1] = i.coordinates[1]
newCoordXYZ[i.label-1][2] = i.coordinates[2]
assemblyInstance.editNode(nodes=assemblyInstance.nodes,coordinates=newCoordXYZ)
The same way you do it for the part, you should do it for assembly instance:
assemblyInstance = mdb.models[modelName].rootAssembly.instances[instanceName]
assemblyInstance.editNode(nodes=assemblyInstance.nodes,coordinates=newCoordXYZ)
Make sure to make your instance independent!
I was having a play around with Python 2.7 and everybody knows that at the start of every program, you always have to import modules. For example:
import random
import time
for x in range(1, 300):
print random.randint(1,100)
time.sleep(1)
print "Done!"
Anyway, I was thinking, why do I have to import all my modules manually? Why doesn't Python just import them all like this.
Sure, I can understand why it does not import like this:
from random import randint
from time import *
for x in range(1, 300):
print randint(1,100)
sleep(1)
print "Done!"
As some function names may clash. But, if you have to define where the function is at the start, so for example random. in random.randint(1,100).
Now modern computers are so powerful, it seems logical to import every module automatically instead of wasting lines of code, and time by having to find which module you need then importing it manually when it can easily be automated.
So, why does python not import every module at startup automatically?
EDIT:
I have made a new version of a little program that imports every module that I can find by running:
import sys
sys.builtin_module_names
Here are the results:
x = int(1000000)
def test():
global x
x -= 1
print "Iterations Left: ", x
import __builtin__
import __main__
import _ast
import _bisect
import _codecs
import _codecs_cn
import _codecs_hk
import _codecs_iso2022
import _codecs_jp
import _codecs_kr
import _codecs_tw
import _collections
import _csv
import _functools
import _heapq
import _hotshot
import _io
import _json
import _locale
import _lsprof
import _md5
import _multibytecodec
import _random
import _sha
import _sha256
import _sha512
import _sre
import _struct
import _subprocess
import _symtable
import _warnings
import _weakref
import _winreg
import array
import audioop
import binascii
import cPickle
import cStringIO
import cmath
import datetime
import errno
import exceptions
import future_builtins
import gc
import imageop
import imp
import itertools
import marshal
import math
import mmap
import msvcrt
import nt
import operator
import parser
import signal
import strop
import sys
import thread
import time
import xxsubtype
import zipimport
import zlib
def start():
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print t.timeit()
start()
Because you don't need all of it. There is no point in loading every library if you don't need them.
EDIT:
I copied my libs folder to a test directory and made it into a package by adding an __init__.py file to it. In this file I added:
import os
import glob
__all__ = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(__file__)+"/*.py")]
I created a test script that contains:
from Lib import *
print('Hello')
When I try to run it in the shell all it does is print 'The Zen of Python' by Tim Peters, opens this webcomic in my browser (2 things I absolutely did not see coming) and throws the following error:
Traceback (most recent call last):
File "C:\Users\Hannah\Documents\dropBox\Python\test\test.py", line 1, in <module>
from Lib import *
AttributeError: 'module' object has no attribute 'crypt'
It takes a noticable amount of time before it does any of this, about 10-15 seconds
Maybe what you would like is a feature that automatically imports the libraries that are used in your script without needing to specify them at the beginning. I found this on the Internet http://www.connellybarnes.com/code/autoimp/
You just need one import at the beginning of your script
from autoimp import *
All other modules are loaded "lazily", i.e. when they are first used.
Example in the interactive shell:
>>> random.random()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined
>>> from autoimp import *
>>> random.random()
0.0679000238267422
From the docs:
For ultimate laziness, place the command "from autoimp import *" in your PYTHONSTARTUP file. Now your interactive session has all modules available by default.
Every module you import takes time to import. Importing every built-in module every time you start Python would kill performance in a lot of important scenarios where new Python interpreters are started frequently.
Python does have a set of modules that are always loaded, its call __builtins__ :).
Python's builtins provide the import statement for you to extend your scope with even more modules! But as other posts have said, deciding your script needs these modules it up to you. -- I have looked into mutating __builtins__ and I promise you, explicitly importing what you need is the better option.
((Big rant about not using from name import * cut from here))
Since most of writing python ultimately becomes packaging and installing that writen python somewhere, this is my goto set of resources for getting a handle on python's infamous import:
Start by sticking to standard tools and libraries (https://packaging.python.org/current/)
Reading and understand The Google Python Standards Guide (https://google.github.io/styleguide/pyguide.html),
Read the Zen of Python (https://www.python.org/dev/peps/pep-0020/)
Be Pythonic (basically adhere to "The Zen of Python"), https://www.youtube.com/watch?v=wf-BqAjZb8M
Supplement your problem-space with tips from The Hitchhikers Guid to Python (http://docs.python-guide.org/en/latest/)
Be preapred to package your code (https://packaging.python.org/distributing/ (Doc), https://github.com/pypa/sampleproject/ (Example))
Being prepared to debug someone else's and, Your own code by getting familiar with tools like:
pdb (import pdb; pdb.set_trace(), > pp variable),
print(help(variable)),
dir(variable),
and pprint.pprint( variable.__dict__ )
In Blender 2.62 I was using this script to display a point:
import bpy
from bpy.props import FloatVectorProperty, IntProperty, FloatProperty
from add_utils import AddObjectHelper, add_object_data
data0=[]
data0.append((float(69.3456), float(36.4562), float(26.8232)))
me0 = bpy.data.meshes.new( name = "point cloud0")
me0.from_pydata( data0, [], [] )
me0.update()
add_object_data(bpy.context, me0, [])
After having updated to Blender 2.67a the execution returns a failure and the following error is reported in the console window:
ImportError: No module named 'add_utils'
Do you have any clue why this should not work anymore?
Thank you :)
Add the missing bpy_extras import at the start of the script
import bpy
import bpy_extras
from bpy.props import FloatVectorProperty, IntProperty, FloatProperty
from bpy_extras import object_utils.object_data_add
from bpy_extras import AddObjectHelper
The API for add_object_data appears to have changed to object_data_add so you'll need to change that in the script too.
object_data_add(bpy.context, me0, [])