I am using the code I have mentioned and I run into the problem.
It works fine for dwg files (dwg to dwg).
When I want to use it on dxf (dxf to dwg) (I am switching the file extension), CAD allows me to select the source file but then error shows.
However, if I manually open the source dxf, and run the command in the dwg the program will work.
My guess there must be an issue with LISP not being able to open dxf.
Can you help?
(vl-load-com)
(command "MODEL" "")
(command "ZOOM" "E")
(setq acobj (vlax-get-acad-object)
acdoc (vla-get-activedocument acobj) ;;== Gets the active document/current drawing
model (vla-get-modelspace acdoc) ;;== To tell AutoCAD which space the new entities should occupy, you need to obtain a pointer to that space.
docs (vla-get-documents acobj)
targets '((0 10000) (15000 10000) (30000 10000))
)
;;== Checking the AutoCAD version as some of the functions are version dependent
(setq dbx
(vla-GetInterfaceObject acobj
(if
(< (setq acver (atoi (getvar "ACADVER"))) 16)
"ObjectDBX.AxDbDocument"
(strcat "ObjectDBX.AxDbDocument." (itoa acver))
)
)
);;== Check end
(setq cntr 0) ;;= Variable to count number of loops to be performed
(setq reference_point (vlax-3d-point 0.0 0.0 0.0)) ;;== creates a point at given coordinates, required for most operations on objects
(while
(and
(<= cntr 0) ;;== loop counter condition === should be 2, set to 0 for testing!!!
(progn
(princ)
(setq file (getfiled "Select file to import lines" (cond (path) ((getvar 'dwgprefix))) "dwg" 2)) ;;== getfiled - Prompts the user for a file name with the standard AutoCAD file dialog box, and returns that file name,
)
;;(setq insertion_point (getpoint "\nSpecify insertion point:(command "._VBASTMT" (strcat "AcadApplication.Documents.Open \" "C:\Users\320049837\Desktop\MRI\TopView.dxf" "\" "")) "))
(setq insertion_point (nth cntr targets)) ;;== Goes through the list of target positions and sets the current target accordingly
(setq insertion_point (vlax-3d-point insertion_point))
;;(command "._VBASTMT" (strcat "AcadApplication.Documents.Open \"" file "\""))
)
(setq path (strcat (vl-filename-directory file) "\\")
doc nil
l nil
)
(vlax-for x docs
(if
(eq (vla-get-fullname x) file)
(setq doc x)
)
)
(or doc (vla-open dbx file :vlax-true))
(vlax-for obj (vla-get-modelspace (cond (doc) (dbx)))
(if
(eq (vla-get-objectname obj) "AcDbPolyline")
(setq l (cons obj l))
)
)
(prompt "n\Stop 1")
(if l
(foreach x
(vlax-invoke (cond (doc) (dbx)) 'copyobjects l model)
(vla-move x reference_point insertion_point)
)
)
(princ (strcat "\n" (itoa (length l)) " lines imported from " (strcase (vl-filename-base file))))
(MRIcolours) ;;==Adding colours for the lines - subfunction)
(MRItexts)
(setq cntr (1+ cntr)) ;;==loop counter increment
)
(vlax-release-object dbx)
(princ)