Rs.command('-_import ...) not working

Hello,

I need to import a couple of dxf-Files and arrange them for further process.

Using MacroEditor following command works:
-_import “D:\import\step01.dxf” y i _Enter

Sadly it doesn’t work with Phyton
import rhinoscriptsyntax as rs
rs.Command(’-_import “D:\import\step01.dxf” y i _Enter’)

The system responds:
Command: -_import
Command: d:\import\step01.dxf
Unknown command: d:\import\step01.dxf
Command: y
Unknown command: y
Command: i
Unknown command: i

Help is needed.
Regards, MillingGuy

Hello - try

rs.Command('-_import ' + chr(34) + 'D:\import\step01.dxf' + chr(34) +' y i _Enter')

-Pascal

Hello Pascal,

doesn’t work either. System output is the same.
based on your suggestion, i experimented a bit:

import rhinoscriptsyntax as rs

filename1 = ‘d:\import\step01.dxf’
filename2 = ‘“d:\import\step01.dxf”’

rs.Command(’-_import d:\import\step01.dxf y i _Enter’)
rs.Command(’_Pause’)
rs.Command(’-_import d:\import\step01.dxf y i _Enter’)
rs.Command(’-_import “d:\import\step01.dxf” y i _Enter’)
rs.Command(’_Pause’)

rs.Command(’-_import ’ + chr(34) + ‘d:\import\step01.dxf’ + chr(34) + ’ y i _Enter’)
rs.Command(’_Pause’)

rs.Command(’-_import ’ + filename1 + ’ y i _Enter’)
rs.Command(’_Pause’)
rs.Command(’-_import “’ + filename1 + '” y i _Enter’)
rs.Command(’_Pause’)
rs.Command(’-_import ’ + chr(34) + filename1 + chr(34) + ’ y i _Enter’)
rs.Command(’_Pause’)

rs.Command(’-_import ’ + filename2 + ’ y i _Enter’)

The output was quite interesting, as sometime the import was done (note I’ve done ‘i’ as an alias to _Mirror trying to call _Mirror some times):

Command: -_import
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): d:\import\step01.dxf
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: -_import
Name of the file to import ( Browse ): d:\import\step01.dxf
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”
Command: _Pause
Command: d:\import\step01.dxf
Unknown command: d:\import\step01.dxf
Command: y
Unknown command: y
Command: i
Command: _Mirror
Start of mirror plane ( 3Point Copy=Yes XAxis YAxis ZAxis ): _Enter
Start of mirror plane ( 3Point Copy=Yes XAxis YAxis ZAxis )

Closer analysis: for each two rs.Command(’-_import …) there is one success in doing the import. This is regardless, which combination of rs.Commands (parameter just as static string, combined with chr(34) or just filename as variable, …)
There is soemewherey a problem in flow control when doing rs.Command as this is also a problem doing:

rs.Command(’_Pause’)
rs.Command(’_Align l 0 ‘)
rs.Command(’_Pause’)
rs.Command(’_Align b 0 ‘)
rs.Command(’_Rotate 0 90)

Here the execution order is rotation first followed with Align Bottom and Align Left last.

Really strange.
Bye, Harald

Here is my .DXF batch import script, maybe that will help… Note I specify all options (even if not needed) and I spell them out completely.

BatchImportDXF.py (1.6 KB)

1 Like

Hello,
@Helvetosaur
thx. I’ll give it a try.

In between I’ve done also some tests…

I thought, if there is a _Enter argument there would be also a _Cancel argument. Surprise: it cancel the operation :slight_smile:
So I thought further: if rs.Command(s) are ordered the wrong way and I call them twice with first one beeing canceled, the second one gets through.
First trial

import rhinoscriptsyntax as rs

filename1 = ‘d:\import\step01.dxf’

rs.Command(’-_import “’ + filename1 + '” y i _Enter’)
rs.Command(’-_import “’ + filename1 + '” y i _Cancel’)

Failed => results in:

Command: _RunPythonScript
Command: -_import
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Cancel
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Error importing file “d:\import\step01.dxf”.

It didn’t work. The “Error importing file…” message seems to come from the cancel task. It is the same as canceling the operation with hitting ESC.

Completely unknownable: why do the system first call both “-_import” and afterwards get over to ask about the parameters.

Second Trial
So I’ll give it another try:

import rhinoscriptsyntax as rs

filename1 = ‘d:\import\step01.dxf’

rs.Command(’_Pause’)
rs.Command(’-_import “’ + filename1 + '” y i _Enter’)
rs.Command(’-_import “’ + filename1 + '” y i _Cancel’)

Failed => result in:

Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Cancel
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Error importing file “d:\import\step01.dxf”.

Now “-_import” is just called once and gets canceled. So I think, execution order is in wrong order but the _Cancel directive stops calling the programatic first “-_import”.

Third trial

import rhinoscriptsyntax as rs

filename1 = ‘d:\import\step01.dxf’

rs.Command(’_Pause’)
rs.Command(’-_import “’ + filename1 + '” y i _Enter’)

Success => results in:

Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”

Interestingly “_Pause” is called before “-_Import”. Compared to above I would have expected a reversed order here as well. So “_Pause” is sure a feature necessary to use here.

Fourth trial:

import rhinoscriptsyntax as rs

filename1 = ‘d:\import\step01.dxf’
filename2 = ‘d:\import\step02.dxf’

rs.Command(’_Pause’)
rs.Command(’-_import “’ + filename1 + '” y i _Enter’)
rs.Command(’_Pause’)
rs.Command(’-_import “’ + filename2 + '” y i _Enter’)
rs.Command(’_Pause’)
rs.Command(’_Rotate 0 90 _Enter’)

Failed => results in:

Command: _Pause
Command: _Rotate
Select objects to rotate: 0
Select objects to rotate: 90
Unknown command: 90
Select objects to rotate: _Enter
Select objects to rotate
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step02.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 13, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step02.dxf”
Command: _Pause
Command: -_import
Name of the file to import ( Browse ): “d:\import\step01.dxf”
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): y
LayoutUnits ( Microns Millimeters Centimeters Meters Kilometers Microinches Mils Inches Feet Miles Angstroms Nanometers Decimeters Dekameters Hectometers Megameters Gigameters Yards Printerpoints Printerpicas Nauticalmiles Astronomicalunits Lightyears Parsecs ): i
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters ): _Enter
Set DWG import options ( ReadUnreferencedLayers=Yes ReadUnreferencedBlocks=Yes ReadUnreferencedLinetypes=Yes WidePlinesAsSurfaces=No IgnoreThickness=No RegionsAsCurves=No LayerMaterialsToColors=No MeshPrecision=Automatic ModelUnits=Millimeters LayoutUnits=Millimeters )
Opened AutoCAD file version Release 12.

Model space objects read: 6, skipped: 0
Paper space objects read: 0, skipped: 0
Block definition objects read: 0, skipped: 0
XRef objects read: 0, skipped: 0
Successfully read file “d:\import\step01.dxf”

Due to the wrong execution order, “_Rotate” is first handled. The actual parts to be imported are thus not rotated.

Conclusio:
rs.Command(s) seems not to be handled the way one is expecting it. Especial if other rs.Command(s) takes place, how would the system then behave?

Tests done with Rhino 7.3.21039.11201

Bye, MillingGuy

Hello @Helvetosaur

your script is apparently working. Did some crosscheck and play around. Having n dxf-files in a folder, your script just loads n-1 files. It always seems to be the first file that is missing.

I rewrite your script using rs.OpenFileNames instead rs.BrowseForFolder and of course it doesn’t work either.

Can you check, if all files are loaded at your side?

Regards, MillingGuy

Btw:

def DXFImportSettings():
e_str = " _ReadUnreferencedLayers=_Yes "
e_str+= "_ReadUnreferencedBlocks=_Yes "
e_str+= "_ReadUnreferencedLinetypes=_Yes "
e_str+= "_WidePlinesAsSurfaces=_No "
e_str+= "_IgnoreThickness=_No "
e_str+= "_RegionsAsCurves=_No "
e_str+= “_LayerMaterialsToColors=_No”
e_str+= “_MeshPrecision=_Automatic”
e_str+= “_ModelUnits=_Millimeters”
e_str+= “_LayoutUnits=_Millimeters”
return e_str

The last 4 parameters are concatenated without a space in between. But this seems to be no problem to the system :thinking:

Hi again,

boahh…: insert a “_Pause” and it’s working.

comm_str="_-Import “+chr(34)+fullpath+chr(34)+sett+” _Enter"
rs.Command(’_Pause’)
rs.Command (comm_str, False)

now all files get loaded. Do also work on my version with selecting the DXF-files.

Hope, some guys from McNeel can bring some light into the whole stuff. Especially what and when “_Pause” is need for.

Regards, Harald

I don’t know what your goal is here, but it seems to me you are going about this a bit bass-ackwards…

Either you go with a 100% macro solution or a scripting solution but mixing both doesn’t work. If possible, I would use native rhinoscriptsyntax methods for anything other than the import function - i.e for rotating use rs.RotateObject() or rs.RotateObjects() etc…

The rs.Command() method is for running native Rhino command strings. It runs the whole string before going on the the next line in the script. While it is possible to use Pauses inside these strings, it is not recommended; something like rs.Command(Pause) by itself has no meaning as Pause is only used inside a Rhino macro, its purpose being to pause a macro for user input as in screen picks. In full-on script mode, this would better be accomplished by something like rs.GetObject() or rs.GetObjects().

Read both the help on macros as well as the rhinoscriptsyntax help.

I don’t see that here so far, all files are imported. Edit: I noticed something that might cause a problem if the file extension is in capital letters i.e. .DXF and not .dxf. I fixed that and a couple of other minor bugs please re-download and try again.

That is an error, now fixed.

BatchImportDXF.py (1.6 KB)

1 Like

Hi @Helvetosaur

What I want to do:

  • load a dxf-files selectable by user
  • each dxf-files should go in a new layer regardless of its origin.
  • all contours coming from the dxf-files must be bottom and left aligned to WC = 0,0,0
  • all contours should be rotated 90° if the user confirms to do so via a message box.

I started to do all parts with scripting. Aligning bottom and left I did not found a script command. So I turned over doing it with rs.Command(’_Align’).
For importing also no script command was found => so I come up to do it also with rs.Command(’_Import’).
Altogether I thought, why not doing rotation also with rs.Command(’_Rotate’).

So I would prefer to do either. Somewhere I’m still missing the track how to get everything up and running with pure scripting. Especially because the available methods are very few.

Not at me. Execution order of two consecutive rs.Command(s) isn’t the one they are written. And I do not use a “_Pause” inside a rs.Command. It is always between rs.Commands where very well the whole procedure is different than if this is not used.

Just n-1 files are loaded. If I put a rs.Command(’_Pause’) before your rs.Command (comm_str, False), all dxf-Files get imported.
importDXF_Helvetosaur1.py (1.7 KB)

Regards, Harald

Don’t see that here - must be something you are doing differently than just running the script - or there is something completely off. The command does not need a Pause because there is nothing to pick onscreen, it’s just a batch import.

In the following .zip are 9 .dxf files - do all 9 import on your end? (unzip the folder first)
ImpDXF.zip (90.3 KB)

What you need to understand is that rhinoscriptsyntax methods do not emulate the native Rhino commands in most cases - they are lower-level functions. To align left lower to a given target point you would need to get the bounding box of the object(s) with rs.BoundingBox() - which gives you a list of 8 points representing the bounding box corners of the object. Then you would create a move function to the target point from the point in the bounding box’s list at index 0 - which is the bottom lower left corner.

Hello @Helvetosaur,

:weary: really strange. I didn’t change any script. All ones are working now. I also deleted all Pause directives. All is still working. Hit me dead, man…
I’m wondering, that new starting (as is normal ending a day and next morning start the PC again) the system would do the magic. If so, when do I know I’ve to restart again?!

And further wondering: the execution order is now doing as expected.
My Rhino-Version didn’t changed. It’s really magic.

:slight_smile: yes, that’s the reason why using rc.Command(s) is so nice. The Align-Command does it all easy: rs.Command(’_Align b 0’) => voila, all (selected) objects are aligned bottom to zero. Doing it with BoundingBox() requires much more coding.

The questions are:

  • why not use something that is available and offered?
  • why shouldn’t user build functions combining RhinoScript and RhinoCommands? In my import case (and perhaps a lot other tasks) it is just possible to do so, because no RhinoScript is availabe to do an import. What is the decision not to take a RhinoCommand but instead write a lot of code to get the same task working?

Thx, MillingGuy

Correct - you will find in any case using rhinoscriptsyntax functions will require more coding than simply calling rs.Command() with some native Rhino function. They are more granular and designed for more flexibility/customizability. Imagine it being more like a load of bricks and some mortar instead of a prefab wall section. If you co further down into RhinoCommon there is even more coding and more power/flexibility. Like getting raw clay and baking your own bricks, and getting sand and cement to mix your own mortar.

No problem at all with that personally.

I didn’t imply that - I said not to try to mix macros with scripts. Yes, there are a few functions that are not available as rhinoscriptsyntax methods, notably everything that has to do with file opening, importing, exporting and saving. There are some RhinoCommon methods for .3dm files but not for other formats.

There are also a few other times when scripting a higher level native Rhino command can be much easier, because that particular Rhino command has a lot of sophistication built into it. However, once you get into it some, I think you will find that scripting with Rhinoscriptsyntax methods gives you more flexibility and control. And if you get down into RhinoCommon, you will find that there are things you can do that neither native Rhino commands nor rhinoscriptsyntax methods can do.

I can give you a quick example with something as simple as a point. With rhinoscriptsyntax, you can use GetPoint() or GetPoints() to get a collection of on-screen point picks and store them as 3DPoint objects to use later. With native Rhino commands all you can do is actually create Rhino points and add them to the document, then have to pick them again later and extract their coordinates.

Yes, that is how it should be. But shouldn’t RhinoScriptSyntax be able to do everything that is possible with RhinoCommands? Why are things like “import from files” missing in RhinoScriptSyntax, making it a non full supporting library.

rs.Command is part of RhinoScriptSyntax. But the parameter itself is nothing but a string with the macro command. So writing a RhinoScriptSyntax using rs.Command is to me the mix of macros and script, which shouldn’t be done. Where’s my mistake?

yes, that for sure. But do we both agree that using rs.command instead of reprogramming a function makes more sense if the desired scope is sufficient (e.g. just a simple rs.Command(‘Align B 0’) would do the whole job of doing n times rs.BoundingBox() followed by n times rs.Move() with calculation routine from/where to position the geometry)

Regards, MillingGuy

Probably because Rhino can open and import around 40 different file types, many with different options. The rhinoscriptsyntax method would thus be very complicated, or it would need dozens of separate methods. As I said, in RhinoCommon, there are methods to deal directly with Rhino 3dm files, but not other formats.

Not really - it’s mostly for dealing with setting options within a single command, not executing a string of commands. The second might work, but I wouldn’t want to rely on it, nor try to debug it if things go south.

No, not necessarily. For one thing debugging more complex scripts becomes very difficult when using rs.command, as you actually step out of the script environment and into the native Rhino environment, then back into the script. If something goes wrong while it’s in the Rhino environment it’s much harder to figure out what. As you noticed with your first attempts above.

But please feel free to write your scripts any way you like. If it works for you, then it’s fine.

Actually in the hands of someone with a bit of experience, scripting can do much more than what is possible with just stringing together native Rhino commands - that’s what its purpose is.