Jump to content

Very Basic VBA


gazzalp

Recommended Posts

Yeah, weve found that problem with some more complex vba routines weve made. At the moment im just trying to learn some simple things - text, hatch viewports and dimensions on a certain layer. But i want to actually understand the code, not just have it written for me. Once i get all those objects worked out ill start moving onto more complex routines. thanks for your help

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • gazzalp

    12

  • rkmcswain

    5

  • SEANT

    4

  • skipsophrenic

    3

Top Posters In This Topic

Posted Images

Argh this is driving me nuts! Ive tried playing arund with that code to insert things like text, hatch, viewports and dimensions so they go on their own layer, but for some reason i can not get it to work. This is the code to add a dimension to a certain spot, but what i want is for autocad to ask where i want the dimension:

 

Sub Example_AddDimAligned()
   ' This example creates an aligned dimension in model space.

   Dim dimObj As AcadDimAligned
   Dim point1(0 To 2) As Double
   Dim 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) = 10#: 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)
   ZoomAll
End Sub

 

Now with the line code, the part:

    Dim point1(0 To 2) As Double
   Dim point2(0 To 2) As Double
   Dim location(0 To 2) As Double

 

instead of saying point1 says start point, end point etc. Do i need to change that for the dimension? And then under the Define dimension i need to change that part of the code to ask me where i want it instead of putting it in at those locations, but for some reason the code is not working...

Link to comment
Share on other sites

EDIT: ive found out how to do that (at least with aligned dimensions so i hope to be able to work out more myself) but one more question, when i add the 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 that? 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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...