Jump to content

VBA calculating spaces in inches to X Y


Recommended Posts

Posted

Hi gays and gals. (using Autocad 2007)

 

This one is making me crazy and it does not help I am new Autocad . :cry:

I have a beam I need to place support 'chairs' underneath.

 

So what I have so far is they can pick the beam and I get the X Y cords back. I convert the X Y to inches using this.

 

'===============================================================================
Private Function Distance(Point1 As Variant, Point2 As Variant) As Double
   '---
   '--- Returns the distance between two points
   '---
   Dim dblDist As Double
   Dim dblXSl As Double
   Dim dblYSl As Double
   Dim dblZSl As Double
   
   '--- Calc distance
   dblXSl = (Point1(0) - Point2(0)) ^ 2
   dblYSl = (Point1(1) - Point2(1)) ^ 2
   dblZSl = (Point1(2) - Point2(2)) ^ 2
   dblDist = Sqr(dblXSl + dblYSl + dblZSl)
   
   '--- Return Distance
   Distance = dblDist

End Function

This seems to work fine. Now I also have a minimum spacing that the support beams must respect. So if my beam is 8 feet (96 inches) and the minimum spacing is 12 inches I would need 8 support chairs.

 

So the question is... How do I convert the inches back to the X Y cords for the insert? My insert code is this:

 

'=================================================================================================
Private Function InsertBlock(ByVal blockpath As String, ByVal rotation As Double, insertionPnt As Variant)
    
   Dim blockobj As AcadBlockReference
    
   '--- set rotation Angle
   rotateAngle = rotation
   rotateAngle = rotation * 3.141592 / 180#
    
   ThisDrawing.ActiveSpace = acModelSpace
    
   Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, blockpath, 1#, 1#, 1#, rotateAngle)
   'Change Modelspace into Paperspace to insert the block into Paperspace
    
End Function

This seems good too. Any help will save what little hair I have left.

Thanks is advance.

 

Steve

Posted

Something like this might serve the purpose. It has not undergone much testing, however.

 

 

Function DivideSpan(ByVal varStPt As Variant, ByVal varEndPt As Variant, intDivisions As Integer) As Variant()
Dim varTemp() As Variant
Dim dblVect(2) As Double
Dim dblDummy(2) As Double
Dim i As Integer
Dim j As Integer
  If UBound(varStPt) = 2 And UBound(varEndPt) = 2 Then
     On Error GoTo Abort
     dblVect(0) = (varEndPt(0) - varStPt(0)) / intDivisions
     dblVect(1) = (varEndPt(1) - varStPt(1)) / intDivisions
     dblVect(2) = (varEndPt(2) - varStPt(2)) / intDivisions
     intDivisions = intDivisions
     ReDim varTemp(intDivisions)
     For i = 0 To intDivisions
        For j = 0 To 2
           dblDummy(j) = varStPt(j) + (dblVect(j) * i)
        Next
        varTemp(i) = dblDummy
     Next
  End If
Abort:
DivideSpan = varTemp
'calling routine should check for empty array
End Function

Posted

Very cool!!!! Thanks a bunch!!!

 

I removed the

 

intDivisions = intDivisions

 

as I did not see what that did.

 

Again, thanks!

Posted
Very cool!!!! Thanks a bunch!!!

 

I removed the

 

intDivisions = intDivisions

 

as I did not see what that did.

 

Again, thanks!

 

Good idea.:) I don't know how that even got there.

Posted

Now I remember. I was originally going to exclude the start and endpoints, by "ReDim"ming at intDivisions - 2, but changed my mind. Apparently I had started making some provisions for it.

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...