0
$\begingroup$

hello i have a really simple problem

if my active object is an mesh i want to do an action, if its an empty another one, ... ect

so i want for example in this case, move the location of the active object only if it's an empty

so i tried

if bpy.context.object.type = 'EMPTY'
    bpy.context.object.location[0] = 8.46184

i really dont understand why it doesnt work, when i type

bpy.context.object.type

in blender python console, i have 'EMPTY' as an response...

what is wrong ?

$\endgroup$

closed as off-topic by batFINGER, Duarte Farrajota Ramos, Scott Milner, aliasguru, p2or Jan 9 at 15:40

  • This question does not appear to be about Blender within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ I'm voting to close this question as off-topic : issues are extremely basic python syntax errors. $\endgroup$ – batFINGER Jan 6 at 3:24
2
$\begingroup$

You are trying to assign 'EMPTY' to "bpy.context.object.type" within an if clause. For checking the value of something, you need to use "==", not "=".

if bpy.context.object.type == 'EMPTY':
    bpy.context.object.location[0] = 8.46184
$\endgroup$
1
$\begingroup$

These are basic syntax errors.

I have voted to close this question as I believe it is an unnecessary question. Since it already has one answer, will provide this as to why.

The same errors will be produced by code completely void of any blender API reference,

if x = 3
    x = 4

and whether in blenders python console, or a python shell or any other python console, you can crunch it in and receive feedback on the errors, as well as variable values etc.

Here is the output of if statement in py console. The writing in red indicates an error. If you are using the text editor, the error statement will be written in the error pop-up on run, and to the system console.

enter image description here

At this point, rather than writing a question:

Copy the error type and paste into google, or another search engine of your choosing

enter image description here

Similarly the first match for python if statement syntax error

After checking out some answers you still don't understand, then write a question. Post the error messages and other details.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.