I have a horizontal sketch segment that was drawn within a drawing view using drawdoc.createline2, and I am trying to create a non-associated dimension that displays the length of this line(top line of a square, whose sides are defined as dblLft, dblRght, dblTop, dblBott). No matter what I do I can't get this to display anything like what I need. Can anyone see what I am doing wrong?
One thing that makes it easier for us to help you out is to show the entire code for this section. If not, we do not know where the dbtop, etc values are coming from. It is very hard to help out with only a snippit of the code.
Have you verified that the point values are correct for placing the dimension?
These variables (dblLft, dblRght, dblTop, dblBott) were filled with dimensions pulled from my models polyline pts. These are the values that were used to create my lines that I am trying to dimension, so yes, I am positive that they are correct. (And yes, they are in meters.)
My sketch is of a simple rectangular box, and my code is simply trying to create a dimension relative to, and displaying the size of, the top horizontal segment of this box. The reason I want to use this non-associated dimension type is only because I don't want my code execution to stop for user approval of a driving dimension. This is just going to be a reference display. My box is defined by TopLeftCorner(dblLft, dblTop, 0), TopRightCorner(dblRght, dblTop, 0), BottomRightCorner(dblRght, dblBott, 0), and BottomLeftCorner(dblLft, dblBott, 0).
Sorry - I tried to make that part of it clear without having to post extensive amounts of code showing how I came up with my polyline pts.
Here is some code that will show what I am trying to do. This creates a front view of the part - if you change it to a right-side view, you should be able to see the dimension. No matter what I change, or how I change it, I can't seem to get it to come out where I want it.(I think in inches, so if your metric, you'll have to change a couple of figures)
Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As ModelDoc2 Dim swDraw As DrawingDoc Dim swSheet As Sheet Dim swView As View Dim swLayerMgr As SldWorks.LayerMgr Dim swLine1 As SketchSegment Dim swDisplDim As DisplayDimension Dim blnRet As Boolean Dim lngwarnings As Long Dim dblLft, dblRght, dblTop As Double Dim swFile, strTmpltNm As String Dim swSelMgr As SldWorks.SelectionMgr
swFile = "C:\Your_Path\Your_SolidPart.SLDPRT"
'Create a new drawing using system default template Set swApp = Application.SldWorks Set swModel = swApp.OpenDocSilent(swFile, _ swDocPART, lngwarnings) strTmpltNm = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing) Set swDraw = swApp.NewDocument(strTmpltNm, 0, 0#, 0#) Set swSelMgr = swDraw.SelectionManager Set swLayerMgr = swDraw.GetLayerManager