PDA

View Full Version : Import An Existing Dimstyle



BeKirra
2010-03-01, 06:18 AM
Hi ALL,
How to import an existing dimstyle (*.dim) by using autolisp?
Your helps are much appreciated.

ccowgill
2010-03-01, 01:35 PM
Hi ALL,
How to import an existing dimstyle (*.dim) by using autolisp?
Your helps are much appreciated.
express tools has the ability to do it, I think that you have to export it first. I would almost think that it would be easier just to write a routine that creates the dimension style from scratch, but it depends on what you are using it for.

TimSpangler
2010-03-01, 04:25 PM
Hi ALL,
How to import an existing dimstyle (*.dim) by using autolisp?
Your helps are much appreciated.


Probably objectdbx. Read the drawing get the dimstyle with all of it properties, then recreate it in the new drawing.

It would take a bit of coding though.

alanjt
2010-03-01, 10:25 PM
Probably objectdbx. Read the drawing get the dimstyle with all of it properties, then recreate it in the new drawing.

It would take a bit of coding though.
You could cheat and just insert a DWG that includes the Dimension style.


(command "_.-insert" "name.dwg" nil)

This would bring in any styles, etc. but cancel the insert before a block is created in the drawing.

Not beautiful, but completely feasible.

TimSpangler
2010-03-02, 12:01 PM
You could cheat and just insert a DWG that includes the Dimension style.


(command "_.-insert" "name.dwg" nil)

This would bring in any styles, etc. but cancel the insert before a block is created in the drawing.

Not beautiful, but completely feasible.

That is a way also. probably the most used way. I think we have standard dwg laying around here like that.

alanjt
2010-03-02, 01:29 PM
That is a way also. probably the most used way. I think we have standard dwg laying around here like that.

Yeah, we just stuck all the styles in one dwg that gets inserted at startup.

ccowgill
2010-03-03, 01:31 PM
You could cheat and just insert a DWG that includes the Dimension style.


(command "_.-insert" "name.dwg" nil)This would bring in any styles, etc. but cancel the insert before a block is created in the drawing.

Not beautiful, but completely feasible. what if the drawing you are inserting it into already has a dimension style by that name? I dont think it will update it (but then again, maybe that is not the OP's case.

alanjt
2010-03-03, 01:35 PM
what if the drawing you are inserting it into already has a dimension style by that name? I dont think it will update it (but then again, maybe that is not the OP's case.

No, it will not overwrite any differences in an existing style of the same name. This is just there to ensure the style exists in the drawing.

BeKirra
2010-03-05, 12:22 AM
what if the drawing you are inserting it into already has a dimension style by that name? I dont think it will update it (but then again, maybe that is not the OP's case.
Well, what I am going to do is:
1) First of all, check the drawing if the dimension style (Preferred_dimstyle) exists by using
(tblsearch "dimstyle" Preferred_dimstyle)
2) If it exists, perform the rest of functions in the routine.
3) If it doesn't exists, import the dimension style by using
(command "dimim" bararbarar...)
then continuing to execute the rest of routine.

The difficulty is to write the 3rd part above.

Thanks for everyone's input.

RobertB
2010-03-05, 12:57 AM
Well, what I am going to do is:
1) First of all, check the drawing if the dimension style (Preferred_dimstyle) exists by using
(tblsearch "dimstyle" Preferred_dimstyle)
2) If it exists, perform the rest of functions in the routine.
3) If it doesn't exists, import the dimension style by using
(command "dimim" bararbarar...)
then continuing to execute the rest of routine.

The difficulty is to write the 3rd part above.If you are doing steps 1-2 in code, why bother with importing a DimStyle in step 3? Why not just create the DimStyle in code? Most of the settings can be done by modifying the system variables and then saving the DimStyle.

BeKirra
2010-03-05, 02:31 AM
If you are doing steps 1-2 in code, why bother with importing a DimStyle in step 3? Why not just create the DimStyle in code? Most of the settings can be done by modifying the system variables and then saving the DimStyle.
Because the mentioned Preferred_dimstyle is a part of the company drawing standard & the entire set of the dimstyles has already been stored in the drawing standard folder.
I need to import these predefined dimstyles to the drawings received from other firms when they have not been found.
There is no doubt that these dimstyles can be inserted to the drawing manually or be created in the code.
But it would be much "easier" to import dimstyles by using routine when having some tasks to follow.

Thanks.

ccowgill
2010-03-05, 12:49 PM
you say that you want to call command dimim, what about actually exporting the dimensions in your company file to the Prefered_Dimensionstyles.dim file, then actually call the express tool dimim to import those dimension styles? The express tool Dimex and dimim are located in the Dimiso.arx file, so possibly you could just call it.

If you are using 2010, this may not work, it appears as though the dimex command exports the dimension styles, but it is all jumbled up and the style names dont transfer. I know that the last time I used it (May of 06) we were using AutoCAD 2005 at the time and it worked great.

RobertB
2010-03-05, 07:28 PM
Because the mentioned Preferred_dimstyle is a part of the company drawing standard & the entire set of the dimstyles has already been stored in the drawing standard folder.
I need to import these predefined dimstyles to the drawings received from other firms when they have not been found.
There is no doubt that these dimstyles can be inserted to the drawing manually or be created in the code.
But it would be much "easier" to import dimstyles by using routine when having some tasks to follow.Try this:

;|
DimStyleImport.lsp
Written by R. Robert Bell
Usage: (i:DimStyleUpdate styleName fqnName)
Returns: T for success, nil for failure
Sample: (I:DimStyleImport "Test" "C:\\Documents and Settings\\rbell\\My Documents\\Test.dwg")
|;

(defun i:DimStyleImport (styleName fqnName / fqnTemp myAcad dbxName myDb sourceDimStyle targetDimStyle)
(and (findfile fqnName)
(setq fqnTemp (vl-filename-mktemp "Dims" (getenv "Temp") ".dwg"))
(vl-file-copy fqnName fqnTemp)
(setq myAcad (vlax-Get-Acad-Object))
(setq dbxName (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'AcadVer)))))
(setq myDb (vla-GetInterfaceObject myAcad dbxName))
(progn (vla-Open myDb fqnTemp) 'T)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ()
(setq sourceDimStyle (vla-Item (vla-Get-DimStyles myDb) styleName)))))))
(setq targetDimStyle (vla-Add (vla-Get-DimStyles (vla-Get-ActiveDocument myAcad))
styleName))
(progn (vla-CopyFrom targetDimStyle sourceDimStyle) T)
(vlax-Release-Object myDb)
(vl-file-delete fqnTemp)))

BeKirra
2010-03-07, 10:39 PM
you say that you want to call command dimim, what about actually exporting the dimensions in your company file to the Prefered_Dimensionstyles.dim file, then actually call the express tool dimim to import those dimension styles? The express tool Dimex and dimim are located in the Dimiso.arx file, so possibly you could just call it.

Again, the entire set of the company dimstyle, in dim file format, has been stored in the folder. ie
Std 1.dim
Std 2.dim
Std 5.dim
Std 10.dim
Std 20.dim
...
And the 1, 2, 5, 10, 20, ... represents the dimscales 1:1, 1:2, 1:5, 1:10, 1:20 respectively.
What I wish to do is to import these dimstyles programmatically.
Obviously, an simple call of "dimim" doesn't work properly in the code.



If you are using 2010, this may not work, it appears as though the dimex command exports the dimension styles, but it is all jumbled up and the style names dont transfer. I know that the last time I used it (May of 06) we were using AutoCAD 2005 at the time and it worked great.
Yes, I have experienced the similar.
From 2000 version to 2010 version, I have never had the correct dimstyle name when importing the dimstyles which was "dimex"ed with the original dimstyle name.
I have to open the dim file & rename it.
Although this is not significant, can this problem be solved with a lisp & how?
Thanks.

BeKirra
2010-03-07, 10:55 PM
Try this:

;|
DimStyleImport.lsp
Written by R. Robert Bell
Usage: (i:DimStyleUpdate styleName fqnName)
Returns: T for success, nil for failure
Sample: (I:DimStyleImport "Test" "C:\\Documents and Settings\\rbell\\My Documents\\Test.dwg")
|;

(defun i:DimStyleImport (styleName fqnName / fqnTemp myAcad dbxName myDb sourceDimStyle targetDimStyle)
(and (findfile fqnName)
(setq fqnTemp (vl-filename-mktemp "Dims" (getenv "Temp") ".dwg"))
(vl-file-copy fqnName fqnTemp)
(setq myAcad (vlax-Get-Acad-Object))
(setq dbxName (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'AcadVer)))))
(setq myDb (vla-GetInterfaceObject myAcad dbxName))
(progn (vla-Open myDb fqnTemp) 'T)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
(function
(lambda ()
(setq sourceDimStyle (vla-Item (vla-Get-DimStyles myDb) styleName)))))))
(setq targetDimStyle (vla-Add (vla-Get-DimStyles (vla-Get-ActiveDocument myAcad))
styleName))
(progn (vla-CopyFrom targetDimStyle sourceDimStyle) T)
(vlax-Release-Object myDb)
(vl-file-delete fqnTemp)))
Thanks for your help.
Could you please give more explanation about your code as I am a beginner?
First of all, I know the "defun c:test ()" means to call a user predefined command, but what does "defun i:test ()" mean? - Cannot find it in the HELP.
And how to get your code works?.
Thanks again.

fclao
2010-03-08, 08:18 AM
Again, the entire set of the company dimstyle, in dim file format, has been stored in the folder. ie
Std 1.dim
Std 2.dim
Std 5.dim
Std 10.dim
Std 20.dim
...
And the 1, 2, 5, 10, 20, ... represents the dimscales 1:1, 1:2, 1:5, 1:10, 1:20 respectively.

sinp...
.

Where I work we have a set of routine which we run at the start of a new drawing, which sets the company standard text and dimstyle setting.

Here is a sample of the coding:


(defun c:dim100 ()
(command "-dimstyle" "r" "standard") ; ; sets the current dimstyle to standard
(setvar "dimaunit" 1) ;; sets variables to company standard
(setvar "dimadec" 2)
(setvar "DIMDEC" 0)
(setvar "dimunit" 2)
(setvar "dimtih" 0)
(setvar "dimtoh" 0)
(setvar "dimtad" 1)
(setvar "dimblk" "_archtick")
(setvar "dimtxsty" "80cl-sc100")
(setvar "dimldrblk" "")
(setvar "dimlfac" 1000)
(setvar "dimclrt" 3)
(setvar "dimasz" (0.20))
(setvar "dimcen" (0.10))
(setvar "dimdli" (0.70))
(setvar "dimdle" (0.10))
(setvar "dimexe" (0.10))
(setvar "dimexo" (0.10))
(setvar "dimgap" (0.10))
(setvar "dimtxt" (0.25))
(command "-dimstyle" "s" "DIM-100") ;; saves the override to a new dimstyle
)



In cases where some rogue employee would mess up the dimstyle settings we just re-run this routine and all settings are restored.

RobertB
2010-03-08, 04:34 PM
Where I work we have a set of routine which we run at the start of a new drawing, which sets the company standard text and dimstyle setting.
...
In cases where some rogue employee would mess up the dimstyle settings we just re-run this routine and all settings are restored.Which is exactly what I mentioned here (http://forums.augi.com/showpost.php?p=1049688&postcount=10). But they insisted on importing even though that's not the most reliable method. I too, far prefer creating the DimStyles via code, since you can overwrite bad definitions.

RobertB
2010-03-08, 04:37 PM
Could you please give more explanation about your code as I am a beginner?
First of all, I know the "defun c:test ()" means to call a user predefined command, but what does "defun i:test ()" mean? - Cannot find it in the HELP.
And how to get your code [to work]?The use of other prefixes is not described in the help files. You can search here for "prefix" and are bound to get several threads, since we have discussed this in the past.

The header of the post shows you both the usage and an example? Do you really need more information on how to get it to work?

BeKirra
2010-03-09, 10:33 PM
Which is exactly what I mentioned here (http://forums.augi.com/showpost.php?p=1049688&postcount=10). But they insisted on importing even though that's not the most reliable method. I too, far prefer creating the DimStyles via code, since you can overwrite bad definitions.
This is a very nice idea & I will do something similar. Thanks to fclao & RoberB.
But my issue is the other case -
I want to insert my dimstyles to someone's drawing & make them stand out.
There is nothing dealing with restoring the dimstyles.
Thanks again.

BeKirra
2010-03-09, 10:40 PM
The use of other prefixes is not described in the help files. You can search here for "prefix" and are bound to get several threads, since we have discussed this in the past.
I will do a search later as I have 3 jobs in hand at the moment.


The header of the post shows you both the usage and an example? Do you really need more information on how to get it to work?
Yes, I do need more info - as I said I am a beginner. Thanks:Oops:

RobertB
2010-03-10, 12:55 AM
Yes, I do need more info ...Command: (I:DimStyleImport "Test" "My Filename.dwg")

"Test" is the name of the dimension style to import.
"My Filename.dwg" is the filename and path to the drawing file that holds the dimension style.

Note that the import routine assumes that you have already checked for that dimension style existing in the current drawing. It will break if you try to import an already existing style.