Importing obj files

Hi there,

I am trying to import the stanford bunny (which I have downloaded as an obj file already) using the following:


but I constantly get the following error message:


AttributeError: module ‘compas’ has no attribute ‘files’


ps. I have made sure that compas is imported by checking its version (0.11.0)

Any tip is appreciated.

are you trying to get the raw data or create a mesh?

if you are trying to get the raw data:

from compas.files import OBJ
obj = OBJ(filepath)
vertices = obj.vertices
faces = obj.faces
edges = obj.lines

if you want to create a mesh:

from compas.datastructures import Mesh
bunny = Mesh.from_obj(filepath)

let me know if that doesn’t work…

unless you specifically need this version, it might also be a good idea to update compas. current version is 0.15.5

1 Like

Hi, thanks for your prompt response! Trying to read an existing mesh and get its raw data (vertices and faces) in this case. The first method didn’t work (vscode complains about 4 ‘problems’):

Instance of ‘OBJ’ has no ‘read’ member
Instance of ‘OBJ’ has no ‘vertices’ member
Instance of ‘OBJ’ has no ‘faces’ member
Instance of ‘OBJ’ has no ‘lines’ member

and it gives the following error message in the output:

Traceback (most recent call last):
File “c:\Users\pnourian\surfdrive\CONFIGRAPHIX_Software_2019\Genesis_Houdini\Houdini_Visualization\20_PythonHoudini_Setup\PY\”, line 18, in
obj = OBJ(filepath)
File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\”, line 29, in init
self.reader = OBJReader(filepath)
File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\”, line 103, in init
File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\”, line 113, in open
with open(self.filepath, ‘r’) as fh:
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\pnourian\Documents\bunny.obj’

the first set of errors is related to your COMPAS version. my suggestion was based on the latest version (0.15.5) which includes some small changes to the readers…

i would just update COMPAS, but if you prefer using the version you have, the code would be something like this:

obj = OBJ(filepath)
vertices = obj.parser.vertices
faces = obj.parser.faces

for the second error, could you print the filepath variable and post it here?

I don’t need to use this version; I wanted the most recent version; have reinstalled everything a couple of days ago. I am surprised to see that my compas is a retro version! I just did “conda update compas” in my terminal and strangely i get the same version:

import os
import numpy as np
import scipy as sp
import compas as compas
import pandas as pd 
# print(folderPath)

the conda update mechanism is a bit weird. just do

conda install COMPAS=0.15.5
1 Like

not sure what the file path error is about. are you sure the file is available in that location?

anyway, i also noticed that the anaconda errors seem to come from your base environment.
i would recommend not using the base environment for anything you do with conda.

think of the base environment as your conda system environment from where you create new environments, update existing ones, or revert to older versions if necessary.

therefore, even if you don’t plan on working on multiple projects in the foreseeable future, it still makes sense to sandbox your work and explorations in a separate environment.

to reset the base do

conda install --revision 1

to create a new environment with COMPAS installed do

conda create -n xxx python=3.7 COMPAS=0.15.5

replace xxx with the name you intend to use.
and don’t forget to activate the environment before you use it…

1 Like

for some reason the installation is failing repeatedly; currently trying conda install -n base compas=0.15.5 -c conda-forge

what do you mean by “failing”?
what fails?

in any case,

it is (i just tried it, albeit in a separate environment :slight_smile: )

conda install -n base -c conda-forge COMPAS=0.15.5


conda install -n base COMPAS=0.15.5 -c conda-forge

Thanks for the additional tips about anaconda!
BTW, did it have to be in uppercase letters? I finally managed to get conda to install this version by running this:
conda create -n arch python=3.7 COMPAS=0.15.5 -c conda-forge

But, now, I am wondering how to navigate to this environment in vscode (I can only choose my python interpreter); becuase I still see the same version (0.11) in my vscode…

no, the uppercase is not necessary. weird though that is works with the arguments in the back. but if it works it works :slight_smile:

you will have to restart vscode to make it aware of the environment.

as soon as you open a python file it will ask for an interpreter and then you should be able to select the python in the arch environment…

1 Like

Managed to navigate to the new environment in vscode when choosing my python interpreter; but again I see that conda version is 0.11 (when I print ). I am getting a feeling that this problem is not related to compas so I apologize for taking your precious time with this; but do you think I am missing something in vscode; or would you recommend uninstalling and installing COMPAS again using these two:
conda uninstall -arch compas
conda install -arch python=3.7 -c conda-forge compas=0.15.5

ps. after uninstalling, I figured out it was still reading compas from the base environment, in spite of having chosen the python interpreter from the specific environment.

i would go through the trouble to set things up properly. it will save you time down the road…

that means removing all current environments, resetting your base environment, and making a dedicated environment for your current work.

it is a bit of extra work but things will work better and behave more predictable afterwards…

1 Like