Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic Question 1

Status
Not open for further replies.

RufussMcGee

Technical User
Jan 7, 2005
117
US
What is an easy way to which your dimstyle. The thing I am trying to do is auto dimenion a part after the user fills out some infomration.

Thanks.
 
Could you insert the part as a block (pre-dimensioned) and then edit after insert?
 
Dimstyle controls different dimension information. For example you might have Standard8 for scale 1.1/2" = 12" and Standard16 for 3/4" = 12". You need to change this variable when dimensioning in model space.

Have tried this code but the enter at the end does not work.

ThisDrawing.SendCommand "-dimstyle R Standard8" & " "

 
Inserting a block with a dimstyle defined in it will bring the dimstyle with it.
 
Still would not resolve the issue of making a certain dimstyle active just a way to create more blocks and dimstyles in a blank Autocad session.
 
Hi Rufuss,

After you create your dimension, assign it the dimstyle you want:

Code:
  Dim objDim As AcadDimension
  ...
  objDim.StyleName = "Standard8"
  objDim.Update

HTH
Todd
 
Have the dimension create in Autocad but when I run the program get the error

Run-time Error '91':
Object Varible or With block variable not set

Even tried to modify your code as follows

Dim objDim as AcadDimStyle

and the did not work.
 
Hi Rufuss,

Are you creating the dimension, or is it already existing?

If you a are creating it:
Code:
  Dim dimObj As AcadDimAligned
  Dim point1(0 To 2) As Double, point2(0 To 2) As Double
  Dim location(0 To 2) As Double
    
  ' Define the dimension
  point1(0) = 5: point1(1) = 5: point1(2) = 0
  point2(0) = 5.5: point2(1) = 5: point2(2) = 0
  location(0) = 5: location(1) = 7: location(2) = 0

  ' Create an aligned dimension object in model space
  Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(point1, point2, location)
  ' Now change it's style:
  dimObj.StyleName = "Standard8"
  dimObj.Update
  ... 
  ..

If the dimension already exists, you'll need to select it using whatever method you like, and then set it to the dimension object:

Code:
  Dim objDim as AcadDimension
  Dim ssetObj as AcadSelectionSet
  
  ' << Create your selection set here >>
  ...
  
  ' Set your objDim object:
  Set objDim = ssetObj(0)

  objDim.StyleName = "Standard8"
  objDim.Update

HTH
Todd
 
Just able to get to VB, now that my job has slowed up a little. What I am trying to do is draw a standard detail and dimension it with min. user input. For the most part all the dimension style are already made in our template. What I need to do is if the part is 48" over less then use dimstyle standard8; 48"-96" standard12; higher standard16.

Tried to run parts of the code listed above and even rewrote parts to try and understand what is happening. This is the code I wrote but it fails at 'set objDim = ssetObj(0)
....................................................
Private Sub CommandButton1_Click()
Dim objDim As AcadDimension
Dim ssetObj As AcadSelectionSet
Dim dimObj As AcadDimAligned
Dim point1(0 To 2) As Double, point2(0 To 2) As Double
Dim location(0 To 2) As Double

' Define the dimension
point1(0) = 5: point1(1) = 5: point1(2) = 0
point2(0) = 5.5: point2(1) = 5: point2(2) = 0
location(0) = 5: location(1) = 7: location(2) = 0

' Create an aligned dimension object in model space
Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(point1, point2, location)

' Set your objDim object:
Set objDim = ssetObj(0)

objDim.StyleName = "Standard8"
objDim.Update
End Sub
........................................................

Any HELP would be great, Thanks.
 
Hi Rufuss,

Sorry for the delayed response...

You probably won't need the line:

Code:
' Set your objDim object:
  Set objDim = ssetObj(0)

Just use your variable dimObj:
Code:
  objDim.StyleName = "Standard8"
  objDim.Update

HTH
Todd
 
Did what you suggested and now have an error that reads....

Run-Time erroe '91':
Object varible or With block variable not set
-----

The code is written as such....

Private Sub CommandButton1_Click()
Dim objDim As AcadDimension
Dim ssetObj As AcadSelectionSet
Dim point1(0 To 2) As Double, point2(0 To 2) As Double
Dim location(0 To 2) As Double

' Define the dimension
point1(0) = 5: point1(1) = 5: point1(2) = 0
point2(0) = 5.5: point2(1) = 5: point2(2) = 0
location(0) = 5: location(1) = 7: location(2) = 0

' Create an aligned dimension object in model space
Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(point1, point2, location)

objDim.StyleName = "Standard8" <<<ERROR ON THIS LINE
objDim.Update
End Sub
-------

The Dimstyle 'Stardard8' is loaded into the drawing. Would caps have anything to do with it?
 
Hi Rufuss,

That error would make sense, remember you don't need objDim, use dimObj...

Code:
  ' Create an aligned dimension object in model space
  Set dimObj = ThisDrawing.ModelSpace.AddDimAligned(point1, point2, location)
 
  [b][red]dimObj[/red][/b].StyleName = "Standard8" 
  [b][red]dimObj[/red][/b].Update

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top