LISP working in AutoCAD but not in BrisCAD
Hi,
I have created a lis to rename layers and layout tab. This works fine in AutoCAD but not in BrisCAD. Can anyone help me why this is happening?
[code]
(defun C:PPR (/ lay layobj diam dwg cnt fun tab lst); = Layer Name Underscores to Hyphens
(vl-load-com)
(setq diam (getstring "Enter pipe diameter [inches]: "))
(setq dwg (getvar 'dwgname))
(while (setq lay (tblnext "layer" (not lay)))
(vla-put-Name
(setq layobj (vlax-ename->vla-object (tblobjname "layer" (cdr (assoc 2 lay)))))
(vl-string-subst diam "diam" (vla-get-Name layobj))
); vla-put-Name
); while loop setting diameter
(while (setq lay (tblnext "layer" (not lay)))
(vla-put-Name
(setq layobj (vlax-ename->vla-object (tblobjname "layer" (cdr (assoc 2 lay)))))
(vl-string-subst (substr dwg 1 (- (strlen dwg) 4)) "dwgname" (vla-get-Name layobj))
); vla-put-Name
); while loop setting assetname from dwg name
(setq tab (vl-filename-base (getvar 'dwgname)))
(vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
(if (not (eq "Model" (vla-get-name lay)))
(setq lst (cons (cons (vla-get-taborder lay) lay) lst))
)
)
(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
(vla-put-name (cdr lay) (strcat tab "" ))
)
(princ)
); defun
[/code]
0
Comments
-
You are renaming PS layouts to the same name. If there is more than one PS layout your code will fail. I should think that the same problem exists in AC. You should enhance your code and before renaming any object check if the new name is not already in use.
[code]: PPR
Enter pipe diameter [inches]: 15
; error : Automation Error 80020009; [IAcadLayout] Error accessing [NAME] property. ErrIndex=0;
Layout already exists[/code]0 -
It is doing in AC what I expect it to do.I am not a very skilled lisp coder, but wouldn't you expect AC en BC to act in the same way?What would I need to change in order to get it to work?0
-
Are you testing with the same dwg? I have a hunch that your AC dwg has only one PS layout.
Try to provide more details and perhaps a dwg file. 'It does not work' is not very informative.
As you can see in my previous post, the BC Lisp engine often gives very good error information.0 -
Hi,This is the DWG I am playing with.In ACAD it works fine but not in BricsCAD.0
-
I think your problem is related to xref dependent layers (there is an xref in the dwg).
In your code you rename all layers, even if the new name if identical to the old name.
BC stumbles if you try to rename an xref dependent layer. Apparently AC does not if the old and new name are the same.
Try this code:
[code](defun C:PPR (/ diam doc dwg nme)
(vl-load-com)
(if
(and
(= 1 (getvar 'dwgtitled))
(setq diam (getstring "Enter pipe diameter [inches]: "))
)
(progn
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq dwg (vl-filename-base (getvar 'dwgname))) ; Filename without extention.
(vlax-for lyr (vla-get-layers doc)
(if
(and
(not (wcmatch (vla-get-name lyr) "*|*")) ; Exclude xref layers.
(wcmatch (vla-get-name lyr) "*diam*,*dwgname*")
(setq nme
(vl-string-subst
dwg
"dwgname"
(vl-string-subst diam "diam" (vla-get-name lyr))
)
)
(not (tblobjname "layer" nme)) ; Check if name is already in use.
)
(vla-put-name lyr nme)
)
)
(if (not (vl-position (strcase dwg) (mapcar 'strcase (layoutlist)))) ; Check if name is already in use.
(vla-put-name (vla-item (vla-get-layouts doc) (car (layoutlist))) dwg)
)
)
)
(princ)
)[/code]0 -
Hi,Thank you. It looks very nice, but unfortunately the layout tab still named 'dwgname'.No errors though in BS.0
-
Are you using V15 perhaps? If that is the case try switching the active layout after executing the Lisp. In V15 (since V15.2.05) there is an update issue with the display of the layout tabs that may also exist when renaming layouts. This has been fixed in V16 (see SR65262 in the Release Notes).0
-
Hi,Yes, I am using v15.I just updated to v16, but the same error occured.Funny thing is that it is working in v14.0
-
Thanks for your feedback. I'll try to test my code on V16 later today.0
-
I have now tested on V16 and find that the SR65262 fix mentioned before, is incomplete in that a similar problem still exists when renaming layouts.
After renaming a layout programmatically the new name does not display until the user, or the program, switches to a different tab.
The code below includes the 'Switch Tab Workaround':
[code](defun C:PPR (/ diam doc dwg nme tab)
(vl-load-com)
(if
(and
(= 1 (getvar 'dwgtitled))
(setq diam (getstring "Enter pipe diameter [inches]: "))
)
(progn
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq dwg (vl-filename-base (getvar 'dwgname))) ; Filename without extention.
(vlax-for lyr (vla-get-layers doc)
(if
(and
(not (wcmatch (vla-get-name lyr) "*|*")) ; Exclude xref layers.
(wcmatch (vla-get-name lyr) "*diam*,*dwgname*")
(setq nme
(vl-string-subst
dwg
"dwgname"
(vl-string-subst diam "diam" (vla-get-name lyr))
)
)
(not (tblobjname "layer" nme)) ; Check if name is already in use.
)
(vla-put-name lyr nme)
)
)
(if (not (vl-position (strcase dwg) (mapcar 'strcase (layoutlist)))) ; Check if name is already in use.
(vla-put-name (vla-item (vla-get-layouts doc) (car (layoutlist))) dwg)
)
;; Start workaround for update tabs issue:
(setq tab (getvar 'ctab))
(setvar 'ctab (car (vl-remove (strcase tab) (cons "MODEL" (mapcar 'strcase (layoutlist))))))
(setvar 'ctab tab)
;; End workaround.
)
)
(princ)
)
[/code]0 -
FYI: I have sent in a support request regarding the issue explained in my previous post.0
-
Thank you very much for your help!0
This discussion has been closed.