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?
Related
I am trying to make a quotes generator in Python. You can see my code below:
from quotefancy import get_quote
from text_to_font.transformations import word_to_ascii
a=get_quote(type='text')
print(word_to_ascii(
phrase=a,
font_size=3,
kerning=1,
font_path='~/fonts/somefont.ttf'
))
While running this script I am getting this error:
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 have raspberry pi acting as MFRC522 card reader. So far I have a script which worked on python 2.7, but when I tried to move to python 3, bizarre thing happened.
I used updated library for it: https://github.com/pimylifeup/MFRC522-python and adjusted my script accordingly
I installed pip3 and spidev
Here is where strange thing happens. If I run demo script from repo above in new folder it works, cool.
But if I put my previous script in the same folder it returns error as below. And after that if I try again to run demo script, same error occurs.
Moving both script to different folder, has the same effect. I can run demo only before my script. Doing that after, is impossible.
Error:
File "/usr/lib/python3.7/re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
My script:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import requests
import signal
import sys
import os
# some functions non related to MFRC522
reader = SimpleMFRC522()
while continue_reading:
try:
id, text = reader.read()
#print id
#print "---"
ver = query_server(id)
if ver == 1:
open_relay(5)
else:
#do something
finally:
time.sleep(0.5)
It's like folder is somehow tainted after firing my script, what am I missing?
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.
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, [])