Code Red > VB(A)

Sending Cell values to AutoCAD

<< < (2/5) > >>

57gmc:
yes, just change the keyword Sub to Function. don't forget the end statement. A function cannot be called directly as a command. It must be called from a Public Sub. The intent is that you would have logic in the Sub to determine what the contents of the argument of the Function should be. The structure could be a simple as:

--- Code - vb.net: --- Public Sub Test ()       Call MyFunction("test string")End Sub Public Function MyFunction(str As String)    Debug.Print strEnd Function

MSTG007:
Excellent! I think I have that part of the code working from what I can see.


This is the VBA,  I select the cell value of A20 "10", then select the button in the ribbon. It now activates CAD.

--- Code: ---Public Sub Test()
   Call MyFunction("test string")
End Sub
 
Public Function MyFunction(str As String)
    Debug.Print str
End Function


Public Sub Z2S(call as iRibbon)
    Call Z2STR("structName String")
End Sub

Public Function Z2STR(structName As String)
 On Error Resume Next
 Set AcadApp = GetObject(, "AutoCAD.Application")
 If Err Then
 Err.Clear
 Set AcadApp = CreateObject("AutoCAD.Application")
 End If
 AppActivate AcadApp.Caption
 AcadApp.Visible = True
 AcadApp.Application.WindowState = acNorm
 AcadApp.ActiveSpace = acModelSpace
 If AcadApp.Documents.Count = 0 Then
 AcadApp.Documents.Add
 End If
  '' Add this line
 ThisDrawing.SetVariable "USERS1", strucName
 AcadApp.ActiveDocument.SendCommand "zm2st" & vbCr
End Function
--- End code ---

However with the revised code with the added "USERS1" variable seems to error out the lisp side.


--- Code: ---(defun c:zm2st (/         C3D       C3DDOC    LOCATION  NTWRK
                NTWRKS    PROD      PRODSTR   PT        STRC
                STRCNAME  STRUCTURES USERS1
               )
....
      (setq ntwrks (vlax-get c3ddoc 'pipenetworks))

      ;;(setq strcname (getstring "\nStructure name to zoom to: " t))

      (setq strucname (getvar "USERS1"))     

      (vlax-for ntwrk ntwrks
....
--- End code ---


--- Code: ---command:.... ; error: bad argument type: stringp nil
--- End code ---

getting closer lol.


57gmc:
In your vba function argument, you designate the argument as "structName", but when you go to use it in the SetVariable statement, you call it "strucName". The latter is missing a "t".

MSTG007:
 :no: lol. great catch. I changed  "strcname" so they are the same in both lsp and vba.

I was able to execute the command and now i get the following:


--- Code: ---Structure "" not found.
from this area lsp
....
(princ (strcat "\nStructure \"" strcname "\" not found.")

--- End code ---

Within the VBA, what piece of the code calls for the cell which is selected to be copied into memory?
Could that be the last step I am missing?


--- Code: ---....
ThisDrawing.SetVariable "USERS1", strcname
....
--- End code ---

57gmc:
I have no idea what you’re doing on the Excel side. You have to make sure you’re passing a valid string. Your Z2S sub is invalid. A sub can’t have an argument and you don’t use the argument in the sub anyway.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version