Hi
I am trying to figure out how to locate the intersection between two lines. The two lines are pointed out by the user, via ILocateCommandEvents.
I have created two class modules; LCE_Element1 and LCE_Element2.
As far as I understand, you can treat no more than one element in each class module. This happens in the ILocateCommandEvents_Accept subroutine. This is why I have created two class modules. In LCE_Element1 the first line is given by the user, AND the LCE_Element2 is called, where the second line is set.
My LCE_Element1 looks like this:
Private Sub ILocateCommandEvents_LocateFilter(ByVal Element As Element, Point As Point3d, Accepted As Boolean) ShowCommand "Intersection" ShowPrompt "Click again to confirm (1)"End Sub
Private Sub ILocateCommandEvents_Accept(ByVal Element As Element, Point As Point3d, ByVal View As View) Dim element1 As Element Set element1 = Element (the first element is now pointed out by the user) CommandState.StartLocate New LCE_Intersection_Element2 (the second class module is called, where the user sets the second element) ShowCommand "Intersection" ShowPrompt "Select second element"End Sub
Private Sub ILocateCommandEvents_LocateFilter(ByVal Element As Element, Point As Point3d, Accepted As Boolean) ShowCommand "Intersection" ShowPrompt "Click again to confirm (2)"End Sub
Private Sub ILocateCommandEvents_Accept(ByVal Element As Element, Point As Point3d, ByVal View As View) Dim element2 As Element Set element2 = Element ShowCommand "Intersection" ShowPrompt "Found"End Sub
Now, the problem is the scope of the variables element1 and element2. These are the two elements I want to find the intersection between, but I cannot access them at the same time.
I have tried to declare public variables, but when I try to update their value in the class modules, the routines fail to execute.
How can I solve this?
EDIT: It seems like I just had to write "Set" when updating the public variables inside the subroutines. I think there is no problem at all.
Best regards
Unknown said:The problem is the scope of the variables element1 and element2
A similar question arises when the primitive command is started from a VBA UserForm: "How do I pass information from my command class back to my UserForm?"
The key to solving that question is to understand that a UserForm is a kind of class. Any class can have member variables, so you can pass a reference from one class to another by setting the corresponding member variable.
We wrote an article to explain that: Communicating with an ILocateCommandEvents class.
Regards, Jon Summers LA Solutions