i can't find the way to assign a material to a CachedGemotry with python scripting.
On staticGeometry i can do it with ".set_material" but the function dont exist on CachedGeometry.
Do you have a solution?
Thank you!
I assume you mean GeometryCache when you talk about CachedGeometry or am I mistaken?
Assuming I'm not (apologies if I am) then you will be able to do this by modifying the 'materials' property on your GeometryCache object.
import unreal
# Gets Pre-existing objects
cached_geo_asset = unreal.load_asset(‘<GEO_CACHE_PATH>’)
mat_asset = unreal.load_asset(‘<MATERIAL_PATH’)
# Display materials before update.
print(‘Before’)
mats = cached_geo_asset.get_editor_property('materials')
print(mats)
# Override the existing materials to use only the one loaded
# above.
cached_geo_asset.set_editor_property('materials', [mat_asset])
# Display materials after update.
print(‘After’)
mats = cached_geo_asset.get_editor_property('materials')
print(mats)
I hope this helps! I haven't used GeometryCache much so I would be curious to hear if this solutions works out for you.
Related
I'm attempting to use Autodesk Inventor's COM API to create a python script that will generate PDFs of a selection on Inventor Drawings, these PDFs will then be processed in particular ways that aren't important to my question. I'm using pywin32 to access the COM API, but I'm not particularly familiar with how COM APIs are used, and the pywin32 module.
This is the extent of the documentation for Inventor's API that I have been able to find (diagram of API Object Model Reference Document), and I have not been able to find documentation for the individual objects listed. As such, I'm basing my understanding of the use of these objects on what I can find from examples online (all in VB or iLogic - Inventor's own simple built-in language).
A big issue I'm coming up against is in creating the objects I'd like to use. Simplified example below:
from win32com.client import *
# user chooses file paths for open and save here...
drawing_filepath = ""
# Open Inventor application, and set visible (so I can tell it's opened for now)
app = Dispatch('Inventor.Application')
app.Visible = True
# Open the file to be saved as a pdf (returns a Document object)
app.Documents.Open(drawing_filepath)
# Cast the opened Document object to a DrawingDocument object (it is guaranteed to be a drawing)
drawing = CastTo(app.ActiveDocument, "DrawingDocument")
# Create and setup a print manager (so can use "Adobe PDF" printer to convert the drawings to PDF)
print_manager = ??? # How can I create this object
# I've tried:
# print_manager = Dispatch("Inventor.Application.Documents.DrawingDocument.DrawingPrintManager") #"Invalid class string"
# print_manager = drawing.DrawingPrintManager() #"object has no attribute 'DrawingPrintManger'
# print_manager = drawing.DrawingPrintManager # same as above
# print_manager = drawing.PrintManger # worked in the end
print_manager.Printer = "Adobe PDF"
print_manager.NumberOfCopies = 1
print_manager.ScaleMode = print_manager.PrintScaleModeEnum.kPrintFullScale
print_manager.PaperSize = print_manager.PrintSizeEnum.kPaperSizeA3
# Print PDF
print_manager.SubmitPrint()
So I can't figure out how to create a DrawingPrintManager to use! You can see I've avoided this issue when creating my DrawingDocument object, as I just happened to know that there is an ActiveDocument attribute that I can get from the application itself.
I also:
don't know what the full list of attributes and methods for DrawingPrintManager are, so I don't know how to set a save location
don't know for sure that the two Enums I'm trying to use are actually defined within DrawingPrintManager, but I can figure that out once I actually have a DrawingPrintManager to work with
If anyone with more experience in using COM APIs or pywin32 can help me out, I'd be really appreciative. And the same if anyone can point me towards any actual documentation of Inventor's API Objects, which would make things a lot easier.
Thanks
Edit: After posting I've almost immediately found that I can get a PrintManager (can't tell if a PrintManager or DrawingPrintManager) by accessing drawing.PrintManager rather than drawing.DrawingPrintManager.
This is a workaround however as it doesn't answer my question of how to create objects within pywin32.
My problem moving forward is finding where I can access the PrintScaleModeEnum and PrintSizeEnum objects, and finding how to set the save location of the printed PDF (which I think will be a a separate question, as it's probably unrelated to the COM API).
I'm not familiar with python and pywin32, but I try to answer your questions.
Documentation of Inventor API is available in local installation "C:\Users\Public\Documents\Autodesk\Inventor 2020\Local Help" or online https://help.autodesk.com/view/INVNTOR/2020/ENU/
Generaly you are not able to create new instances of Inventor API objects. You must obtain them as a result of appropriate method or property value.
For example:
You CAN'T do this
doc = new Inventor.Document()
You MUST do this
doc = app.Documents.Add(...)
With print manager is this
print_manager = drawing.PrintManger
# this returns object of type Inventor.DrawingPrintManager
# when drawing is of type Inventor.DrawingDocument
See this for more details
Hey stackoverflow community,
i’m new to this forum and to python developing in general and have a problem with Alexa/ Python overriding the similar named variable from different files.
In my language learning skill I want Alexa to specifically link a “start specific practice” intent from the user to a specific practice file and from this file to import an intro, keyword and answer to give back to the user.
My problem with the importing, is that Python takes the last imported file and overrides the statements of the previous files.
I know I could probably change the variable names according to the practices but then wouldn't I have have to create a lot of individual handler functions which link the user intent to a specific file/function and basically look and act all the same?
Is there a better way more efficient of doing the specifying of those variables when importing or inside the functions?
import files and variables
from übung_1 import intro_1, keywords_1, real_1
from übung_2 import intro_1, keywords_1, real_1
working with the variables
def get_practice_response(practice_number):
print("get_practice_response")
session_attributes = {}
card_title = "Übung"
number = randint(0, len(keywords_1))
print(intro_1 + keywords_1[number])
speech_output = intro_1 + keywords_1[number]
session_attributes["answer"] = real_1[number]
session_attributes["practice_number"] = practice_number
session_attributes["keyword"] = keywords_1[number]
reprompt_text = "test"
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output, reprompt_text, should_end_session))
I expected giving out the content of the specifically asked file and not variable content from the most recent files.
Sadly I haven't found a solution for this specific problem and hope someone could help me pointing me in the right direction.
Thank you very much in advance.
Might be easiest to import the modules like so:
import übung_1
import übung_2
The refer to the contents as übung_1.intro_1, übung_2.intro_1, übung_1.keywords_1 and so on.
As you point out, these two lines
from übung_1 import intro_1, keywords_1, real_1
from übung_2 import intro_1, keywords_1, real_1
don't work the way you want because the second import overrides the first. This has to happen because you can't have two different variables in the same namespace called intro_1.
You can get around this by doing
import übung_1
import übung_2
and then in your code you explicitly state the namespace you want:
print(übung_1.intro_1 + übung_1.keywords_1[number])
New to python, I'm trying to fine tuning the plotnine graph, and explore what can be done in the theme() function. I'm just wondering what is the general way to find out what else is available for me to play with.
theme(plot_title = element_text(size=10, text='tile'),
axis_title_y = element_text(size=7, text='tlab'),
axis_title_x = element_text(size=7,text='xlab'))
In plotnine, they are called themeables.
I am trying to create a script that would help me automate the creation of a spine rig, but I am running into a problem. I am following the tutorial provided here and I am working on the step where you skin the curve to the IK joints.
However, when I try to use mc.bindSkin(), I keep getting an error:
Error: RuntimeError: file[directory]/maya/2016.5/scripts\createRigSpine.py line 200: Maya command error)
It's too late right now to for me to do much experimenting, but I was hoping someone could help me, or tell me if I'm using the wrong commands.
mc.select(crvSpine, jntIkMidSpine, jntIkChest)
mc.bindSkin(crvSpine, jntIkMidSpine, jntIkChest, tsb=True)
(have also tried mc.bindSkin() and mc.bindSkin(tsb=True))
Ideally, I want the settings to be:
Bind To: Selected Joints
Bind Method: Closest Distance
Skinning Method: Classic Linear
Normalize Weights: Interactive
Edit: I wanted to use skinCluster, not bindSkin.
you should use the skinCluster command to bind your curve to the joints - and you can actually do it without selecting anything!
Try this:
import maya.cmds as mc
influences = [jntIkMidSpine, jntIkChest]
scls = mc.skinCluster(influences, crvSpine, name='spine_skinCluster', toSelectedBones=True, bindMethod=0, skinMethod=0, normalizeWeights=1)[0]
# alternatively, if you don't want such a long line of code:
#
influences = [jntIkMidSpine, jntIkChest]
kwargs = {
'name': 'spine_skinCluster', # or whatever you want to call it...
'toSelectedBones': True,
'bindMethod': 0,
'skinMethod': 0,
'normalizeWeights': 1
}
scls = mc.skinCluster(influences, crvSpine, **kwargs)[0]
# OR just use the short names for the kwargs...
#
influences = [jntIkMidSpine, jntIkChest]
scls = mc.skinCluster(influences, crvSpine, n='spine_skinCluster', tsb=True, bm=0, sm=0, nw=1)[0]
If you wanted to, you could also explicitly set the weights you want for each cv of the curve. You could use the skinPercent command, or even just use setAttr for the various weight attrs in the skinCluster (that's a little more difficult, but not much)
cmds.bindSkin() command made for binding bones to geometry. It's not suitable for binding to IK's only. So you need to assign what joint you need to bind to.
For example:
import maya.cmds as mc
mc.select('ikHandle1','nurbsCircle1','joint5')
mc.bindSkin('ikHandle1','nurbsCircle1','joint5')
# the order of selection is vital
For constraining selected objects use the commands like this:
mc.pointConstraint('ikHandle1','nurbsCircle1', weight=5.0)
To find out what constraints are available to you, use Rigging module – Constrain menu – Parent, Point, Orient, Scale, Aim, Pole Vector.
I was using the wrong command. mc.skinCluster is what I wanted to use, not mc.bindSkin.
Since hours I try to solve a problem I have with Maya / MEL / Python.
I have a script to set values of a fluid container.
E.g. setAttr "fluidShape1.densityDissipation" 0.2
Works great...
My problem: Actually it is not possible to change the value using the interface (see image). Is there a way to find out if the "text box" is enabled?
Thanks!!
P.S. I cant upload the image :(. But I hope you guys know what i mean
To find out if the attribute is settable, use
getAttr -settable your_object.your_attribute
it will return 1 if you can set the attribute using setAttr and 0 if you can't.
If the value is grayed out in the UI the attribute is locked, you can unlock it with
setAttr -lock 0 your_object.your_attribute
If the value is purple in the UI it's driven by a connection of some kind, you'll need to use the hypergraph or the listConnections command to find out what's driving it and decide if you want to override the connection.
I already tried the -settable flag, but for some reason this is not working in my case.
Ok, lets say I create a FluidContainer. The density is set to zero, by using this command:
setAttr "fluidShape1.densityMethod" 0;
By using the -settable flag
getAttr -settable "fluidShapeq.densityScale"
the result is 1. But I can not change the corresponding slider.
But still it is possible to change the values by using setAttr... That is confusing for me!
ok I think I found a "solution" for my problem, but I think I can do better.
I use the following command to get the "grougID" of the slider and the field:
import maya.cmds as cmds
txt = "attrFieldSliderGrp214"
cmds.attrFieldSliderGrp( txt, q=True, l=True ) # Density Scale
And now I can usethe enable field by:
gray = cmds.attrFieldSliderGrp(txt, q=True, en=True ) # True/False
This works fine for me.
def gui():
cmds.window()
cmds.columnLayout( adjustableColumn=True )
#since density support only upto 3 setting max to 3
getCurrentInd = int(cmds.getAttr("fluidShape1.densityMethod"))
cmds.intSlider( min=0, max=3, value=getCurrentInd, step=1, cc=updateDens)
cmds.showWindow()
def updateDens(value):
cmds.setAttr("fluidShape1.densityMethod", value)
gui()
By Interface if I understand that you mean the AttributeEditor, you could try this.
import pymel.core as pc
def findAEFieldByLabel(label='Dissipation', field_type=pc.ui.AttrFieldSliderGrp):
for i in pc.ui.PyUI('MainAttributeEditorLayout').walkChildren():
if isinstance(i, pc.ui.RowLayout):
name = i.name()
try:
grp = field_type(name)
if grp.getLabel() == label:
return grp
except:
pass
print findAEFieldByLabel().getEnable()
I used pymel here because it helps you find the type of a python ui. Well ... not quite however! because it recognized attrFieldSliderGrps as RowLayouts