View Full Version : Linetype Query / Reassign
bcgatti
2007-10-04, 02:05 PM
I have a lisp routine (attached to this post) that I put together yesterday that renames Microstation DGN linetypes to AutoCAD linetypes at the layer level then it reloads the AutoCAD linetypes from acad.lin. Then it saves the current layer state in the file, makes all items editable then changes all entities to color bylayer then it resets the layer state.
I originally thought that this routine was only needed for files that were freshly translated from Microstation that do not have any existing AutoCAD linetypes. However, I now need to modify it so that if an AutoCAD linetype exists it will reassign all layers that have the corresponding DGN Style to the AutoCAD equivalent.
I get the "linetype already exists" message for the existing linetypes and I am stuck.
What I hope to accomplish is this... ex: if the linetype HIDDEN already exists in the file the lisp routine should query and reassign all layers that contain “DGN Style 2” as their linetype to have HIDDEN as their assigned linetype.
I have hit a wall and I do not know how to proceed with this routine. Any suggestions or help would be appreciated.
Brett
Avatart
2007-10-04, 02:41 PM
Hmmm, that's a tricky little tinker.
I am assuming that the renamed Micr*Stati*n linetypes are, or possible are, different from the AutoCad linetypes that you are renaming them to?
If NOT, then you could test to see if a linetype exists and then change your objects to that linetype, or rename the linetype if it does not exist (I think that makes some sense).
If they are different, then I think you will have to think of something else, like renaming the AutoCad linetype to a holding name and translating the MStn names? Dunno if that would work though.
Mike_R
2007-10-04, 03:03 PM
Okay, without going too deeply into it, I've added a few lines into your cond statement. What I've done is just added one test to see if both linetypes are there, and if so, change all the objects with the old DGN linetype to the ACAD linetype.
(defun C:ltr ()
(setvar "CMDECHO" 0)
(setvar "HIGHLIGHT" 0)
(cond
((and
(= (tblsearch "ltype" "DGN Style 0"))
(= (tblsearch "ltype" "CONTINUOUS"))
)
(command "-change" (ssget "_X" '((6 . "DGN Style 0"))) "Properties" "LType" "CONTINUOUS" "")
)
((= (tblsearch "ltype" "DGN Style 0"))
);END COND
(command "-rename" "lt" "DGN Style 0" "CONTINUOUS"))
(cond
((= (tblsearch "ltype" "DGN Style 1"))
(command "-rename" "lt" "DGN Style 1" "DOT"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 2"))
(command "-rename" "lt" "DGN Style 2" "HIDDEN"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 3"))
(command "-rename" "lt" "DGN Style 3" "DASHED"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 4"))
(command "-rename" "lt" "DGN Style 4" "DASHDOT"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 5"))
(command "-rename" "lt" "DGN Style 5" "PHANTOM"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 6"))
(command "-rename" "lt" "DGN Style 6" "DIVIDE2"))
);END COND
(cond
((= (tblsearch "ltype" "DGN Style 7"))
(command "-rename" "lt" "DGN Style 7" "CENTER"))
);END COND
(command "-linetype" "load" "CONTINUOUS,DOT,HIDDEN,DASHED,DASHDOT,DIVIDE,CENTER,PHANTOM" "ACAD.LIN" "" "" "" "" "" "" "" "" "")
(command "-layer" "state" "save" "temp" "" "" "")
(command ".LAYER" "T" "*" "")
(command ".LAYER" "ON" "*" "")
(command ".CHPROP" "ALL" "" "C" "BYLAYER" "")
(command "-layer" "state" "restore" "temp" "" "")
(setvar "HIGHLIGHT" 1)
(setvar "CMDECHO" 1)
)
Would doing basically this solve your dilemma, or is there something I'm not understanding?
Avatart
2007-10-04, 03:07 PM
I see where you are coming from, I was thinking of doing a single tblsearch for the ACAD linetype, if True then change the objects to the ACAD linetype, if not True then rename the MStn LType to the ACAD one.
Mike_R
2007-10-04, 03:13 PM
I see where you are coming from, I was thinking of doing a single tblsearch for the ACAD linetype, if True then change the objects to the ACAD linetype, if not True then rename the MStn LType to the ACAD one.
I was just trying to keep the format he already had. Since he's using (cond), there is no "ELSE" option like with an if statement.
Checking for both is just a redundancy, since there's probably not going to be all of the DGN linetypes in every drawing tested.
bcgatti
2007-10-04, 03:21 PM
Actually all of the Microstation DGN lines are already assigned "bylayer" so filtering by linetype is not exactly what I am looking to do.
What I need to do is to reassign linetypes (in the layer command) if they already exist and to rename the DGN linetypes and load the corresponding AutoCAD linetypes if they don't already exist.
Hopefully this makes sense.
So, basically, you want to search the layers table to check what linetype is assigned to that layer. If the linetype is a DGN style, then check for the preferred DWG style linetype. If it doesn't exist, then load it.
bcgatti
2007-10-04, 03:52 PM
So, basically, you want to search the layers table to check what linetype is assigned to that layer. If the linetype is a DGN style, then check for the preferred DWG style linetype. If it doesn't exist, then load it.
This is partially correct.
I do want to check the layers table as described in your posting. Then I need to reassign the DGN styles to the corresponding AutoCAD styles (at the layer level), then reload the AutoCAD styles to be certain the the AutoCAD linetype definition is the one that is assigned to the layers.
I guess if I had to compare it to something that already exists in AutoCAD, it would be that I am trying to come up with a "Linetype Merge" similar to "Layer Merge (laymrg)" but without having to select items manually. This is not an exact comparison, but it is the closest that I could find in the AutoCAD commands.
Maybe this is what you were saying and I just misinterpreted it.
Thanks.
Avatart
2007-10-04, 04:00 PM
This is partially correct.
I do want to check the layers table as described in your posting. Then I need to reassign the DGN styles to the corresponding AutoCAD styles (at the layer level), then reload the AutoCAD styles to be certain the the AutoCAD linetype definition is the one that is assigned to the layers.
Maybe this is what you were saying and I just misinterpreted it.
Thanks.
So all you need do then (I think) is tblsearch for the ACAD linetypes (maybe into a list?), tblsearch the DGN LTYPES, then rename accordingly.
How are you planning to deal with the difference between a MStn dotted linetype and an ACAD dotted linetype?
bcgatti
2007-10-04, 04:06 PM
So all you need do then (I think) is tblsearch for the ACAD linetypes (maybe into a list?), tblsearch the DGN LTYPES, then rename accordingly.
How are you planning to deal with the difference between a MStn dotted linetype and an ACAD dotted linetype?
I believe that this is along the path of what I am looking for.
I'm not that concerned about differences between the DGN and DWG Linetypes because at the end of the routine I am reloading the AutoCAD linetypes.
Avatart
2007-10-04, 04:14 PM
I believe that this is along the path of what I am looking for.
I'm not that concerned about differences between the DGN and DWG Linetypes because at the end of the routine I am reloading the AutoCAD linetypes.
And are these drawing fresh out of MStn? If they are then you could probably PURGE out all the ACAD linetypes and just rename?
bcgatti
2007-10-04, 04:24 PM
And are these drawing fresh out of MStn? If they are then you could probably PURGE out all the ACAD linetypes and just rename?
The lisp routine that I posted at the beginning of this thread was written for freshly translated MStn files and it does work just fine for them. After the fact, I realized that it would need to be used on "combo" ( translated files that were developed in MStn and then finished in AutoCAD) files as well. These "combo" files have some AutoCAD linetypes in them already.
Avatart
2007-10-04, 04:44 PM
The lisp routine that I posted at the beginning of this thread was written for freshly translated MStn files and it does work just fine for them. After the fact, I realized that it would need to be used on "combo" ( translated files that were developed in MStn and then finished in AutoCAD) files as well. These "combo" files have some AutoCAD linetypes in them already.
So this really is a two stage routine;
Stage 1: Change layer linetype from MStn to ACAD if ACAD linetype exists.
Stage 2: Rename MStn linetypes to ACAD names if ACAD linetypes do not exist.
Mike_R
2007-10-04, 04:54 PM
Okay, here we go.... Try this one out instead then. I hope it works, I had to figure out MAPCAR to get it going. ;)
(defun c:ltr (/ acaddocument)
(setq acaddocument (vla-get-activedocument (vlax-get-acad-object)))
(setvar "CMDECHO" 0)
(setvar "HIGHLIGHT" 0)
(vlax-for layer (vla-get-layers acaddocument)
(mapcar
(function
(lambda (DGNltype ACADltype)
(if (= (vla-get-linetype layer) DGNltype)
(vla-put-linetype layer ACADltype)
()
)
)
)
'("DGN Style 0" "DGN Style 1" "DGN Style 2" "DGN Style 3" "DGN Style 4" "DGN Style 5" "DGN Style 6" "DGN Style 7")
'("CONTINUOUS" "DOT" "HIDDEN" "DASHED" "DASHDOT" "PHANTOM" "DIVIDE2" "CENTER")
)
)
(command "-linetype" "load" "CONTINUOUS,DOT,HIDDEN,DASHED,DASHDOT,DIVIDE,CENTER,PHANTOM" "ACAD.LIN" "" "" "" "" "" "" "" "" "")
(command "-layer" "state" "save" "temp" "" "" "")
(command ".LAYER" "T" "*" "")
(command ".LAYER" "ON" "*" "")
(command ".CHPROP" "ALL" "" "C" "BYLAYER" "")
(command "-layer" "state" "restore" "temp" "" "")
(setvar "HIGHLIGHT" 1)
(setvar "CMDECHO" 1)
)
Lemme know how it turns out.
Cheers!! :beer:
bcgatti
2007-10-04, 05:05 PM
Mike,
I am getting the following error when I attempt to run this with your addition...
; error: bad argument type: VLA-OBJECT nil
Brett
Avatart
2007-10-04, 05:08 PM
Mike,
I am getting the following error when I attempt to run this with your addition...
; error: bad argument type: VLA-OBJECT nil
Brett
I think you need to stick (vl-load-com) at the top of the file, to load the VLisp extensions.
Mike_R
2007-10-04, 05:22 PM
Actually, I forgot to set the acaddocument variable in the routine. It's a global variable that I have set in my acaddoc.lsp...
Code has been edited, should work now.
bcgatti
2007-10-04, 05:31 PM
Thanks for all the assistance on this, but it appears that you have something loaded on your computer that I do not.
I get the following error upon executing this "- ; error: Automation Error. Key not found"
Avatart
2007-10-04, 05:33 PM
Thanks for all the assistance on this, but it appears that you have something loaded on your computer that I do not.
I get the following error upon executing this "- ; error: Automation Error. Key not found"
Have you put the the vl-load-com line in? You need to have that to load the Visual Lisp sub-routines, like vla-get-layers.
bcgatti
2007-10-04, 05:41 PM
Have you put the the vl-load-com line in? You need to have that to load the Visual Lisp sub-routines, like vla-get-layers.
It is there, unless I put it in the wrong place or don't have the correct syntax. Here is what I have...
(defun c:ltr (/ acaddocument)
(vl-load-com)
(setq acaddocument (vla-get-activedocument (vlax-get-acad-object)))
(setvar "CMDECHO" 0)
(setvar "HIGHLIGHT" 0)
(vlax-for layer (vla-get-layers acaddocument)
(mapcar (function (lambda (DGNltype ACADltype)
(if (= (vla-get-linetype layer) DGNltype)
(vla-put-linetype layer ACADltype) () ) ) ) '("DGN Style 0" "DGN Style 1" "DGN Style 2" "DGN Style 3" "DGN Style 4" "DGN Style 5" "DGN Style 6" "DGN Style 7") '("CONTINUOUS" "DOT" "HIDDEN" "DASHED" "DASHDOT" "PHANTOM" "DIVIDE2" "CENTER") ) )
(command "-linetype" "load" "CONTINUOUS,DOT,HIDDEN,DASHED,DASHDOT,DIVIDE,CENTER,PHANTOM" "ACAD.LIN" "" "" "" "" "" "" "" "" "")
(command "-layer" "state" "save" "temp" "" "" "")
(command ".LAYER" "T" "*" "")
(command ".LAYER" "ON" "*" "")
(command ".CHPROP" "ALL" "" "C" "BYLAYER" "")
(command "-layer" "state" "restore" "temp" "" "")
(setvar "HIGHLIGHT" 1)
(setvar "CMDECHO" 1)
)
Mike_R
2007-10-04, 05:48 PM
Hmmmm... Strange, I'm running vanilla ACAD, so I doubt it could be having something extra loaded.
Try this; close and reopen ACAD, type vlide. Then file/new and paste this into the new window. Then, select debug/animate. Then run it from the AutoCAD command line and tell me what line it stops at.
Avatart
2007-10-04, 05:53 PM
Hmmmm... Strange, I'm running vanilla ACAD, so I doubt it could be having something extra loaded.
Try this; close and reopen ACAD, type vlide. Then file/new and paste this into the new window. Then, select debug/animate. Then run it from the AutoCAD command line and tell me what line it stops at.
I just tried that in my R2006ABS and it worked fine.
Avatart
2007-10-04, 05:54 PM
One thought; would you have to strcase the linetypes to ensure compatibility?
Mike_R
2007-10-04, 06:01 PM
The error he's getting implies that it's not finding a particular property key, such as LineType or Layers... Strcase may be helpful, but I don't wanna have to rewrite that bit of the code unless absolutely necessary. ;)
bcgatti
2007-10-04, 06:15 PM
Well, it ran all the way through (in the VLisp window) with an New / Empty AutoCAD file and it also ran all the way through (in the VLisp window) with a "real" file even though the routine itself did not run in the "real" file.
It does run with no errors in a New / Empty file, but as soon as I use a "real" file it returns to the following error:
Command: appload
ltr-augi.lsp successfully loaded.
Command: ltr
; error: Automation Error. Key not found
Command: 'VLIDE
Which version of AutoCAD is being used?
Avatart
2007-10-04, 06:21 PM
Which version of AutoCAD is being used?
...and are there any Xrefs in the file you are testing it on, they can make a right pigs ear of your program if you don't allow for them.
Bear in mind the Xref linetypes will try and translate too, which they can't, but thier layers can change linetype :?.
bcgatti
2007-10-04, 06:22 PM
AutoCAD 2007 - English SP2
Mike_R
2007-10-04, 06:24 PM
Send me a copy of the DWG your getting the error with. I'd like to see the actual layer properties myself and maybe that'll help find the problem. Send it by PM if there's confidentiality issues.
You might try (re)loading the linetypes into your drawing first and then work with mike's solution. Hopefully this will work.
(defun c:ltr (/ ACADDOCUMENT LAYER TEMPSS)
(vl-load-com)
(setvar "CMDECHO" 0)
(setvar "HIGHLIGHT" 0)
(vl-cmdf "_.linetype")
(foreach n '("DOT" "HIDDEN" "DASHED" "DASHDOT" "PHANTOM" "DIVIDE2"
"CENTER")
(if (null (tblsearch "LTYPE" n))
(vl-cmdf "Load" n "acad.lin")
(vl-cmdf "Load" n "acad.lin" "Yes")
)
)
(vl-cmdf "")
(vlax-for layer (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
(mapcar
(function
(lambda (DGNltype ACADltype)
(if (= (vla-get-linetype layer) DGNltype)
(progn
(if (null (tblsearch "LTYPE" ACADltype))
(vl-cmdf "linetype" "Load" ACADltype "acad.lin" "")
)
(vla-put-linetype layer ACADltype)
)
)
)
)
'("DGN Style 0" "DGN Style 1" "DGN Style 2"
"DGN Style 3" "DGN Style 4" "DGN Style 5"
"DGN Style 6" "DGN Style 7"
)
'("CONTINUOUS" "DOT" "HIDDEN" "DASHED"
"DASHDOT" "PHANTOM" "DIVIDE2" "CENTER"
)
)
)
(vl-cmdf "_.layer")
(vl-cmdf "State" "Save" "Temp" "" "")
(vl-cmdf "Thaw" "*")
(vl-cmdf "On" "*")
(vl-cmdf "")
(if (setq tempSS (ssget "_X"))
(progn
(setq tempSS nil)
(vl-cmdf ".Chprop" "ALL" "" "C" "ByLayer" "")
)
)
(vl-cmdf "_.layer" "state" "restore" "temp" "" "")
(vl-cmdf "_.layer" "state" "delete" "temp" "" "")
(setvar "HIGHLIGHT" 1)
(setvar "CMDECHO" 1)
)
bcgatti
2007-10-04, 06:43 PM
Since I could not figure out how to attach a file to a PM, here it is.
Once again, thanks to all of you who have taken a look at this today.
Brett
Mike_R
2007-10-04, 06:57 PM
Opie hit it on the head. The problem is that those linetypes haven't been loaded into the drawing, so they have to be preloaded at the beginning of the routine. Otherwise, VLisp won't find the linetype in the drawing and return the error, "Key not found".
Opies code works great on it.
Reputation added (again) to Opie.
Cheers! :beer:
bcgatti
2007-10-04, 07:01 PM
Opie's code does do exactly what I was looking for.
If I happen to run into Opie, Mike.127154 and / or Avatart at AU - I owe each of you fine folks (Opie, Mike.127154, Avatart) a beer.
Again, thanks to all for their input and assistance.
Mike_R
2007-10-04, 07:55 PM
I won't be at AU... Unfortunately. But thanks anyway! :beer:
On a sidenote, how do I get my name changed? I'm sick of the 127154 bit...
I won't be at AU... Unfortunately. But thanks anyway! :beer:
On a sidenote, how do I get my name changed? I'm sick of the 127154 bit...
I was wondering how long you were going to take to request that. ;) Try this page (http://www.augi.com/forums/default.asp?page=480) and follow the links from there.
Mike_R
2007-10-04, 08:19 PM
Thanks again Opie.
Have a :beer: on me!
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.