Grasshopper

algorithmic modeling for Rhino

Hi, please excuse my noobness.. I'm attempting to export geometry from gh using a custom ghpython component. I've imported dxfwrite

(from here: https://pypi.python.org/pypi/dxfwrite/1.2.0#downloads

but I receive this msg when trying to run their sample code:

My hope is to be able to export groups of rectangles as a dxf file with multiple layers for use with a cnc machine. Any help pointing me in the right direction would be much appreciated.

thanks

Views: 1130

Attachments:

Replies to This Discussion

further to my question, when you download then import dxfwrite into the code, how does python know where to look for it? I was surprised there seems to be no need to supply a path when importing.

This is a question that many people starting with Python have :)

https://docs.python.org/2/tutorial/modules.html#the-module-search-path

In Rhino there's also a visual editor for that. You can manually add folders in the Tools -> Options menu. GhPython, additionally, adds the folder where you have your .ghx (Grasshopper) file saved.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi,

there was a missing closed parenthesis, ) , at the end of line 7.

Also, you need to specify a folder more precisely. Other than that, it seems to work nicely here.

I hope this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

thanks Giulio, I will give this a try tonight and move on to the next step.

cheers

Success! Now I would like to work out how to use the component inputs for gh geometry instead of generating it inside the component. I wonder if anyone has some simple examples I could refer to?

thanks

Hi Rustboy

this works pretty much like in the _EditPythonScript editor. If 'Type Hint' for inputs is unchanged, x will be a rhinoscript Guid, with which you can use rs.CurveStartPoint(x), etc... y, z will be strings, u will be a Boolean True/False value.

This is because Python is dynamic, that we can just start using variables. If you need to force some special type to inputs, you can change 'type hint'. Please note: Line, Curve, etc are RhinoCommon (import Rhino) types.

Does it help?
There are several more examples on the forum, too, but don't be afraid to open a new discussion and ask about new specific things.

Thanks,

Giulio

--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi Giulio, thanks for the reply. I left the type hint unchanged as you said, and tried to insert the rectangle into the code using dxfwrite (shown in attached image). I can't tell if this is something the dxfwrite library was designed to do - I only see examples for creating geometry within python - not importing gh geometry which is what I want to do. You can see in the image that "GUID has no attribut dxf.."  It recognizes the x input so I'm making progress but I need to bring in exisiting rectangles from gh. Is there possibly some code from Rhino I could insert to accomplish this?

much appreciated

Hi Rustboy

Rhino does not know about dxfwrite, and dxfwrite does not know about Rhino. This means that you will have to translate types yourself. You can see that dxf.line((fromX,fromY), (toX,toY)) creates a line.

So, if you are using rhinoscriptsyntax, for a line, you have to get fromX and fromY using:

fromX = rs.CurveStartPoint(crv_id).X
fromY = rs.CurveStartPoint(crv_id).Y

etc..

Does it help?
As you can see, there is some work. Also, you need to decide how to handle the Z component of point coordinates, if you use that specific call.

I am actually curious why you would want to start with that specific library - Rhino can export dxf with one click, right? (just making sure you are aware of that)

Giulio

--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2020   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service