gazzalp Posted January 13, 2009 Posted January 13, 2009 I didnt get any answers in my previous thread, so ill ask here:when i add a dimension, it will only put it in model space (which isnt too bad, because 99% of the time thats what i want, but would like the option to be able to do it in either) but it doesnt take into account the dimscale - it seems it always put the dimscale in at one. How do i change the code to fix the dimscale and also have it so i can put the dimension in model or paperspace? This is the code i have: Sub AddAlignedDimension() Dim objNewLayer As AcadLayer Dim varFirstPoint As Variant Dim varSecondPoint As Variant Dim varTextLocation As Variant Dim ObjDimAligned As AcadDimAligned Set objNewLayer = ThisDrawing.Layers.Add("Dimensions") objNewLayer.color = acWhite 'define the dimension varFirstPoint = ThisDrawing.Utility.GetPoint(, "Select first point: ") varSecondPoint = ThisDrawing.Utility.GetPoint(varFirstPoint, _ "Select second point: ") varTextLocation = ThisDrawing.Utility.GetPoint(, _ "Pick Dimension Text Location: ") 'Create an Aligned Dimension Set ObjDimAligned = ThisDrawing.ModelSpace.AddDimAligned(varFirstPoint, _ varSecondPoint, varTextLocation) ObjDimAligned.Layer = "Dimensions" ObjDimAligned.Update End Sub Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 Hey gazzalp, I am not well versed in VBA, However AutoCADs dimension variable have a default setting. When creating a dimstyle you need to set your dimension variables and save them to to the name of the dimension style you are trying to create. I have just posted a lisp program that does this under Dimension Style Manager. If you understand autolisp, This program may give you some ideas on how to go about this. Just give it a look, Everything in the program is well explained. Good Luck, The Buzzard Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 gazzalp, It seems as if your trying to invoke a type of dimension command and expect it to look a certain way by setting the dimvars. These are two different commands. The dimstyle needs to be created first and set current before you create the dimension. Once again when the dimstyle is being created, You need to save that style to a name. Then you can invoke a dimension command and it will assume the properties of that current dimension style. I hope this is clear to you. The Buzzard Quote
gazzalp Posted January 13, 2009 Author Posted January 13, 2009 Hmmm that doesn't completely make sense to me... when i use the original autocad dimension button to add a dimension, it inputs the scale at whatever scale the dimscale is set to IE: in paperspace usually 100, or in layoutspace usually 1. This is exactly what i want. However using VBA it always puts the dimension in at 1:1. I really didn't think i would have to do anything in VBA to get it to come in right, considering that in VBA im not setting the scale to anything - therefore i would have thought that when using the VBA macro it adds the dimension in at whatever scale im working with at the time. It really should have anything to do with dimension style i dont think... Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 If you run dimscale command globally it does not make the dimension scale in two different scales between paper and model space. What ever it is set to at the time remains that way until you change it. Also how are you inserting a dimension? Is the dimension premade like a block? Or are you creating it using the dim command. What ever dimscale that you set prior to creating a dimension will be used for that dimension regardless of where it is placed. I am not sure what it is that you are trying to do. I do not know how it can prompt you for a scale. You either set it ahead of time before you make the dimension or you make dimension styles with different settings and set those before you run dim command. I have never heard of being prompted for a scale. They are two different commands. I am not sure now what the goal is. I will leave this to someone who would know better. This not is clear to me. Sorry Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 I do not notice anything in your code that would change the dimension scale to 1. Are you running another code in the background that could possibly effect this? That is kind of strange that your setting would change for no reason. Is this the full code you have so far or is there more to it? Do you want the code to automatically know if its in paper space or model space and change the dimscale accordingly? I do not mean to come off critical, But I do not understand in thr first place as to whay anyone would dimension in paper space to start with. This is what viewports are for. I do not understand what the advantage is to dimensioning this way. I have come across people who have been doing things this way. Does not mean this is wrong, But there are easier ways. I am not sure that I can help you here, But do you also program in lisp? Quote
gazzalp Posted January 13, 2009 Author Posted January 13, 2009 Buzzard, i started programming in lisp but then my boss said that VBA is the way to go. To make it more clear, forget i said anything about modelspace - you are correct, we shouldnt really have to dimension in modelspace and for the most part we dont. So back to my main question, we work with a few different dimension scales ie: 1:20 when drawing concrete details, 1:100/150 when drawing plans, 1:5 when drawing steelwork details etc. So when we are in paper space depending on what we are working on we will have different dimscales set for different drawings (as above). This VBA routine ALWAYS puts the dimension on at scale 1:1. I dont want it to ask me what dimension scale i want, i want it to be able to realise that my dimension scale is set to something particular (in this example we'll say im working on concrete details, at 1:20) so my dimscale would be 20. Therefore when i do the VBA routine it should put the dimension in at scale 20, not 1 like it always does (as you can imagine then the dimension shows up really small). We have no other programs/routines running that would make it default to 1, and the code i put here is the full code. When i use the autocad button it comes out correct - puts it in at 1:20, or 1:100 or whatever my dimscale is set to, yet when i use this VBA routine it always comes in at 1. Hope this makes it more clear Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 gazzalp Again I do not program in VBA. I posted recently a Dimension Style Manager that has all the scales built in that you require and then some. If you want, give it a try, Maybe it will save you alot of headaches. Any changing to that program I may be able to help you with. That up to you. Just let me know, The Buzzard Quote
borgunit Posted January 13, 2009 Posted January 13, 2009 Sounds like you will need to select or have the program figure out scale based on the viewport and its scale that you are selecting in. The first part of the program will need to take a point you are selecting and then cycle through the viewports available (remember they can overlap - problematic?). Once you have it, read its scale and adjust accordingly. Does this sound reasonable? Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 The way my program works, You just pick the scale, and it tells you the recommended viewport setting. All defaults were set to my liking, But can be changed to yours. Is this OK with you? Quote
RickyD302 Posted January 13, 2009 Posted January 13, 2009 wouldn't you want to get the dimscale and see what it is and if its not what you want change it? dim dblDimScale dblDImSCale = ThisDrawing.Getvariable "DIMSCALE" if dblDimscale 100 then ThisDRawing.setVarialble "DIMSCALE", 100 else ...... or something like this You would check to see what space your in and then change scales based on that too. THis is what I use to check space then ' see if user is in model space or paper space Dim blnWhichSpace As Boolean If ThisDrawing.ActiveSpace Then blnWhichSpace = True Else blnWhichSpace = ThisDrawing.MSpace End If Then my code to place objects is (block in this case) If blnWhichSpace Then Set Handle2use = ThisDrawing.ModelSpace.InsertBlock(HandleLocPT, BlkName, Xscale, Yscale, Zscale, BlkRotate) Else Set Handle2use = ThisDrawing.PaperSpace.InsertBlock(HandleLocPT, BlkName, Xscale, Yscale, Zscale, BlkRotate) End If Quote
The Buzzard Posted January 13, 2009 Posted January 13, 2009 When I need to dimension I should know the correct dimscale to use based on experience. It should not be rocket science to set the correct dimscale. My program is also in lisp and as I mentioned I do not program in VBA. If you can help with this problem I am more then willing to step aside. I am just trying to help the best I can. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.