CreateLinearDim4 - What am I doing wrong ?

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?
dblXTxtPos = dblLineCenter
dblYTxtPos = dblTop + Inch_to_Meter(0.25)
dblDimVal = swLine1.GetLength
dblTxtHght = swModel.GetDefaultTextHeight()
vntDimP1 = Array(dblLft, dblTop, 0)
vntDimP2 = Array(dblRght, dblTop, 0)
vntDimPlaneDef = Array(dblLft, dblBott, 0)
vntDimEx1 = Array(dblLft, dblTop + Inch_to_Meter(0.062), 0)
vntDimEx2 = Array(dblRght, dblTop + Inch_to_Meter(0.062), 0)
vntDimTxtPos = Array(dblLft, dblTop + Inch_to_Meter(0.062), 0)
Set swDispDim = swDraw.CreateLinearDim4(vntDimP1, vntDimP2,
vntDimPln, _
vntDimEx1, vntDimEx2, vntDimTxtPos, dblDimVal, 0,
dblTxtHght)
My dimension with these figures comes out in the center of my sketched
square(origin point), with the text and a single arrow displayed - nothing
else.
Has anyone ever used this, or know of a code sample somewhere?
Thank You
Reply to
What-a-Tool
Loading thread data ...
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?
Reply to
SWX-VAR-JP
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.
Thanks
Reply to
What-a-Tool
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
Set swSheet = swDraw.GetCurrentSheet blnRet = swDraw.ActivateSheet(swSheet.GetName) blnRet = swSheet.SetScale(1, 1, False, False)
'swModel is my Part Document (.SLDPRT) swFile = swModel.GetTitle blnRet = swDraw.CreateDrawViewFromModelView(swFile, _
"*Front", (5.75 / 39.3701), (4.25 / 39.3701), 0) blnRet = swDraw.ActivateView("Drawing View1") Set swView = swSelMgr.GetSelectedObject(1) swView.SetDisplayTangentEdges2 2
'Create a new layer to draw a sketch segment in blnRet = swDraw.CreateLayer("TestLayer", "Test", _ 0, swLineCONTINUOUS, swLW_NORMAL, True) blnRet = swLayerMgr.SetCurrentLayer("TestLayer")
'Draw my sketch segment dblLft = -2 / 39.701 dblRght = 2 / 39.701 dblTop = 1 / 39.701 Set swLine1 = swDraw.CreateLine2(dblLft, dblTop, 0, _ dblRght, dblTop, 0) '----------------------------------------------------------------------------------- Dim dblXTxtPos, dblYTxtPos, dblDimVal, dblTxtHght As Double Dim vntDimP1, vntDimP2, vntDimPln, vntDimEx1, vntDimEx2, _ vntDimTxtPos As Variant
'Try and insert non-associative dimension dblXTxtPos = (swLine1.GetLength / 2) + dblLft dblYTxtPos = dblTop + (0.25 / 39.701) dblDimVal = swLine1.GetLength dblTxtHght = swModel.GetDefaultTextHeight()
'Define left pt and right pt of dimension vntDimP1 = Array(dblLft, dblTop, 1 / 39.701) vntDimP2 = Array(dblRght, dblTop, 1 / 39.701) 'This, along with above 2 pt.'s, defines the sketch plane vntDimPln = Array(dblRght, dblTop, 0) 'These define the start and end extension line pt.'s vntDimEx1 = Array(dblLft, dblTop + (0.0625 / 39.701), (1 / 39.701)) vntDimEx2 = Array(dblRght, dblTop + (0.0625 / 39.701), (1 / 39.701)) 'This defines the text position vntDimTxtPos = Array(dblXTxtPos, dblYTxtPos, 1 / 39.701)
Set swDisplDim = swDraw.CreateLinearDim4(vntDimP1, vntDimP2, vntDimPln, _ vntDimEx1, vntDimEx2, vntDimTxtPos, dblDimVal, 0, dblTxtHght)
swModel.GraphicsRedraw2
Set swApp = Nothing Set swModel = Nothing Set swDraw = Nothing Set swSheet = Nothing Set swView = Nothing Set swLayerMgr = Nothing Set swLine1 = Nothing Set swSelMgr = Nothing End Sub
Reply to
What-a-Tool

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.